@abyss-project/console 1.0.72 → 1.0.75

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.
@@ -1,9 +1,11 @@
1
- import { ICreateInternalTicketSectionParams, ICreateInternalTicketSectionBody, IListInternalTicketSectionParams, IUpdateInternalTicketSectionParams, IUpdateInternalTicketSectionBody, IDeleteInternalTicketSectionParams, IGetInternalTicketSectionStatsParams, ICreateInternalTicketCategoryParams, ICreateInternalTicketCategoryBody, IListInternalTicketCategoryParams, IListInternalTicketCategoryQuery, IUpdateInternalTicketCategoryParams, IUpdateInternalTicketCategoryBody, IDeleteInternalTicketCategoryParams, ICreateInternalTicketPriorityParams, ICreateInternalTicketPriorityBody, IListInternalTicketPriorityParams, IListInternalTicketPriorityQuery, IUpdateInternalTicketPriorityParams, IUpdateInternalTicketPriorityBody, IDeleteInternalTicketPriorityParams, ICreateInternalTicketSectionResponse, IListInternalTicketSectionResponse, IUpdateInternalTicketSectionResponse, IDeleteInternalTicketSectionResponse, IGetInternalTicketSectionStatsResponse, ICreateInternalTicketCategoryResponse, IListInternalTicketCategoryResponse, IUpdateInternalTicketCategoryResponse, IDeleteInternalTicketCategoryResponse, ICreateInternalTicketPriorityResponse, IListInternalTicketPriorityResponse, IUpdateInternalTicketPriorityResponse, IDeleteInternalTicketPriorityResponse } from '../types';
1
+ import { ICreateInternalTicketSectionParams, ICreateInternalTicketSectionBody, IListInternalTicketSectionParams, IUpdateInternalTicketSectionParams, IUpdateInternalTicketSectionBody, IDeleteInternalTicketSectionParams, IArchiveInternalTicketSectionParams, IUnarchiveInternalTicketSectionParams, IGetInternalTicketSectionStatsParams, ICreateInternalTicketCategoryParams, ICreateInternalTicketCategoryBody, IListInternalTicketCategoryParams, IListInternalTicketCategoryQuery, IUpdateInternalTicketCategoryParams, IUpdateInternalTicketCategoryBody, IDeleteInternalTicketCategoryParams, ICreateInternalTicketPriorityParams, ICreateInternalTicketPriorityBody, IListInternalTicketPriorityParams, IListInternalTicketPriorityQuery, IUpdateInternalTicketPriorityParams, IUpdateInternalTicketPriorityBody, IDeleteInternalTicketPriorityParams, ICreateInternalTicketSectionResponse, IListInternalTicketSectionResponse, IUpdateInternalTicketSectionResponse, IDeleteInternalTicketSectionResponse, IArchiveInternalTicketSectionResponse, IUnarchiveInternalTicketSectionResponse, IGetInternalTicketSectionStatsResponse, ICreateInternalTicketCategoryResponse, IListInternalTicketCategoryResponse, IUpdateInternalTicketCategoryResponse, IDeleteInternalTicketCategoryResponse, ICreateInternalTicketPriorityResponse, IListInternalTicketPriorityResponse, IUpdateInternalTicketPriorityResponse, IDeleteInternalTicketPriorityResponse } from '../types';
2
2
  export declare const createInternalTicketSection: (params: ICreateInternalTicketSectionParams, body: ICreateInternalTicketSectionBody) => Promise<ICreateInternalTicketSectionResponse>;
3
3
  export declare const listInternalTicketSection: (params: IListInternalTicketSectionParams) => Promise<IListInternalTicketSectionResponse>;
4
4
  export declare const updateInternalTicketSection: (params: IUpdateInternalTicketSectionParams, body: IUpdateInternalTicketSectionBody) => Promise<IUpdateInternalTicketSectionResponse>;
5
5
  export declare const deleteInternalTicketSection: (params: IDeleteInternalTicketSectionParams) => Promise<IDeleteInternalTicketSectionResponse>;
6
6
  export declare const getInternalTicketSectionStats: (params: IGetInternalTicketSectionStatsParams) => Promise<IGetInternalTicketSectionStatsResponse>;
7
+ export declare const archiveInternalTicketSection: (params: IArchiveInternalTicketSectionParams) => Promise<IArchiveInternalTicketSectionResponse>;
8
+ export declare const unarchiveInternalTicketSection: (params: IUnarchiveInternalTicketSectionParams) => Promise<IUnarchiveInternalTicketSectionResponse>;
7
9
  export declare const createInternalTicketCategory: (params: ICreateInternalTicketCategoryParams, body: ICreateInternalTicketCategoryBody) => Promise<ICreateInternalTicketCategoryResponse>;
8
10
  export declare const listInternalTicketCategory: (params: IListInternalTicketCategoryParams, query?: IListInternalTicketCategoryQuery) => Promise<IListInternalTicketCategoryResponse>;
9
11
  export declare const updateInternalTicketCategory: (params: IUpdateInternalTicketCategoryParams, body: IUpdateInternalTicketCategoryBody) => Promise<IUpdateInternalTicketCategoryResponse>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteInternalTicketPriority = exports.updateInternalTicketPriority = exports.listInternalTicketPriority = exports.createInternalTicketPriority = exports.deleteInternalTicketCategory = exports.updateInternalTicketCategory = exports.listInternalTicketCategory = exports.createInternalTicketCategory = exports.getInternalTicketSectionStats = exports.deleteInternalTicketSection = exports.updateInternalTicketSection = exports.listInternalTicketSection = exports.createInternalTicketSection = void 0;
3
+ exports.deleteInternalTicketPriority = exports.updateInternalTicketPriority = exports.listInternalTicketPriority = exports.createInternalTicketPriority = exports.deleteInternalTicketCategory = exports.updateInternalTicketCategory = exports.listInternalTicketCategory = exports.createInternalTicketCategory = exports.unarchiveInternalTicketSection = exports.archiveInternalTicketSection = exports.getInternalTicketSectionStats = exports.deleteInternalTicketSection = exports.updateInternalTicketSection = exports.listInternalTicketSection = exports.createInternalTicketSection = void 0;
4
4
  const __1 = require("..");
5
5
  const createInternalTicketSection = async (params, body) => {
6
6
  const response = await __1.AbyssConsoleCore.axios.post(`/internal-ticket-config/${params.projectId}/section`, body);
@@ -27,6 +27,16 @@ const getInternalTicketSectionStats = async (params) => {
27
27
  return response.data;
28
28
  };
29
29
  exports.getInternalTicketSectionStats = getInternalTicketSectionStats;
30
+ const archiveInternalTicketSection = async (params) => {
31
+ const response = await __1.AbyssConsoleCore.axios.put(`/internal-ticket-config/${params.projectId}/section/${params.internalTicketSectionId}/archive`);
32
+ return response.data;
33
+ };
34
+ exports.archiveInternalTicketSection = archiveInternalTicketSection;
35
+ const unarchiveInternalTicketSection = async (params) => {
36
+ const response = await __1.AbyssConsoleCore.axios.put(`/internal-ticket-config/${params.projectId}/section/${params.internalTicketSectionId}/unarchive`);
37
+ return response.data;
38
+ };
39
+ exports.unarchiveInternalTicketSection = unarchiveInternalTicketSection;
30
40
  const createInternalTicketCategory = async (params, body) => {
31
41
  const response = await __1.AbyssConsoleCore.axios.post(`/internal-ticket-config/${params.projectId}/category`, body);
32
42
  return response.data;
package/dist/index.d.ts CHANGED
@@ -166,6 +166,8 @@ type AbyssConsoleCoreSDK = {
166
166
  list: typeof internalTicketConfigApi.listInternalTicketSection;
167
167
  update: typeof internalTicketConfigApi.updateInternalTicketSection;
168
168
  delete: typeof internalTicketConfigApi.deleteInternalTicketSection;
169
+ archive: typeof internalTicketConfigApi.archiveInternalTicketSection;
170
+ unarchive: typeof internalTicketConfigApi.unarchiveInternalTicketSection;
169
171
  getStats: typeof internalTicketConfigApi.getInternalTicketSectionStats;
170
172
  };
171
173
  category: {
package/dist/index.js CHANGED
@@ -270,6 +270,8 @@ class AbyssConsoleCore {
270
270
  list: internalTicketConfigApi.listInternalTicketSection,
271
271
  update: internalTicketConfigApi.updateInternalTicketSection,
272
272
  delete: internalTicketConfigApi.deleteInternalTicketSection,
273
+ archive: internalTicketConfigApi.archiveInternalTicketSection,
274
+ unarchive: internalTicketConfigApi.unarchiveInternalTicketSection,
273
275
  getStats: internalTicketConfigApi.getInternalTicketSectionStats,
274
276
  },
275
277
  category: {
@@ -7,7 +7,6 @@ export interface ICreateInternalTicketSectionBody {
7
7
  color?: string;
8
8
  icon?: string;
9
9
  order?: number;
10
- requirePriorityReason?: boolean;
11
10
  }
12
11
  export interface IListInternalTicketSectionParams {
13
12
  projectId: string;
@@ -18,16 +17,23 @@ export interface IUpdateInternalTicketSectionParams {
18
17
  }
19
18
  export interface IUpdateInternalTicketSectionBody {
20
19
  name?: string;
21
- description?: string;
22
- color?: string;
23
- icon?: string;
20
+ description?: string | null;
21
+ color?: string | null;
22
+ icon?: string | null;
24
23
  order?: number;
25
- requirePriorityReason?: boolean;
26
24
  }
27
25
  export interface IDeleteInternalTicketSectionParams {
28
26
  projectId: string;
29
27
  internalTicketSectionId: string;
30
28
  }
29
+ export interface IArchiveInternalTicketSectionParams {
30
+ projectId: string;
31
+ internalTicketSectionId: string;
32
+ }
33
+ export interface IUnarchiveInternalTicketSectionParams {
34
+ projectId: string;
35
+ internalTicketSectionId: string;
36
+ }
31
37
  export interface IGetInternalTicketSectionStatsParams {
32
38
  projectId: string;
33
39
  internalTicketSectionId: string;
@@ -37,15 +43,16 @@ export interface ICreateInternalTicketCategoryParams {
37
43
  }
38
44
  export interface ICreateInternalTicketCategoryBody {
39
45
  name: string;
40
- sectionId: string;
46
+ internalTicketSectionId: string;
41
47
  color?: string;
42
48
  description?: string;
49
+ order?: number;
43
50
  }
44
51
  export interface IListInternalTicketCategoryParams {
45
52
  projectId: string;
46
53
  }
47
54
  export interface IListInternalTicketCategoryQuery {
48
- sectionId?: string;
55
+ internalTicketSectionId?: string;
49
56
  }
50
57
  export interface IUpdateInternalTicketCategoryParams {
51
58
  projectId: string;
@@ -57,6 +64,7 @@ export interface IUpdateInternalTicketCategoryBody {
57
64
  description?: string;
58
65
  order?: number;
59
66
  isEnabled?: boolean;
67
+ isArchived?: boolean;
60
68
  }
61
69
  export interface IDeleteInternalTicketCategoryParams {
62
70
  projectId: string;
@@ -67,16 +75,19 @@ export interface ICreateInternalTicketPriorityParams {
67
75
  }
68
76
  export interface ICreateInternalTicketPriorityBody {
69
77
  name: string;
70
- sectionId: string;
78
+ internalTicketSectionId: string;
71
79
  color?: string;
80
+ description?: string;
72
81
  level: number;
73
- label?: string;
82
+ order?: number;
83
+ isDefault?: boolean;
84
+ requirePriorityReason?: boolean;
74
85
  }
75
86
  export interface IListInternalTicketPriorityParams {
76
87
  projectId: string;
77
88
  }
78
89
  export interface IListInternalTicketPriorityQuery {
79
- sectionId?: string;
90
+ internalTicketSectionId?: string;
80
91
  }
81
92
  export interface IUpdateInternalTicketPriorityParams {
82
93
  projectId: string;
@@ -85,10 +96,13 @@ export interface IUpdateInternalTicketPriorityParams {
85
96
  export interface IUpdateInternalTicketPriorityBody {
86
97
  name?: string;
87
98
  color?: string;
99
+ description?: string;
88
100
  level?: number;
101
+ order?: number;
89
102
  isDefault?: boolean;
90
- label?: string;
91
103
  isEnabled?: boolean;
104
+ requirePriorityReason?: boolean;
105
+ isArchived?: boolean;
92
106
  }
93
107
  export interface IDeleteInternalTicketPriorityParams {
94
108
  projectId: string;
@@ -6,9 +6,9 @@ export interface ICreateInternalTicketParams {
6
6
  export interface ICreateInternalTicketBody {
7
7
  title: string;
8
8
  description: string;
9
- sectionId: string;
10
- priorityId?: string;
11
- categoryId?: string;
9
+ internalTicketSectionId: string;
10
+ internalTicketPriorityId: string;
11
+ internalTicketCategoryId?: string;
12
12
  priorityReason?: string;
13
13
  }
14
14
  export interface IPaginateInternalTicketParams {
@@ -16,8 +16,8 @@ export interface IPaginateInternalTicketParams {
16
16
  }
17
17
  export interface IPaginateInternalTicketQuery extends QueryPaginate {
18
18
  status?: InternalTicketStatus;
19
- priorityId?: string;
20
- categoryId?: string;
19
+ internalTicketPriorityId?: string;
20
+ internalTicketCategoryId?: string;
21
21
  sectionId?: string;
22
22
  isArchived?: boolean;
23
23
  search?: string;
@@ -35,8 +35,8 @@ export interface IUpdateInternalTicketBody {
35
35
  title?: string;
36
36
  description?: string;
37
37
  status?: InternalTicketStatus;
38
- priorityId?: string;
39
- categoryId?: string;
38
+ internalTicketPriorityId?: string;
39
+ internalTicketCategoryId?: string;
40
40
  sectionId?: string;
41
41
  assignedToUserId?: string | null;
42
42
  priorityReason?: string;
@@ -61,7 +61,6 @@ export interface ICreateInternalTicketMessageParams {
61
61
  export interface ICreateInternalTicketMessageBody {
62
62
  content: string;
63
63
  replyToMessageId?: string;
64
- mentionedUserIds?: string[];
65
64
  }
66
65
  export interface IUpdateInternalTicketMessageParams {
67
66
  projectId: string;
@@ -17,6 +17,14 @@ export type IUpdateInternalTicketSectionResponse = IResponse<IUpdateInternalTick
17
17
  export interface IDeleteInternalTicketSectionData {
18
18
  }
19
19
  export type IDeleteInternalTicketSectionResponse = IResponse<IDeleteInternalTicketSectionData>;
20
+ export interface IArchiveInternalTicketSectionData {
21
+ internalTicketSection: IInternalTicketSection;
22
+ }
23
+ export type IArchiveInternalTicketSectionResponse = IResponse<IArchiveInternalTicketSectionData>;
24
+ export interface IUnarchiveInternalTicketSectionData {
25
+ internalTicketSection: IInternalTicketSection;
26
+ }
27
+ export type IUnarchiveInternalTicketSectionResponse = IResponse<IUnarchiveInternalTicketSectionData>;
20
28
  export interface IGetInternalTicketSectionStatsData {
21
29
  total: number;
22
30
  open: number;
@@ -2,13 +2,13 @@ import { IInternalTicket } from './internal-ticket.model';
2
2
  import { IInternalTicketSection } from './internal-ticket-section.model';
3
3
  export interface IInternalTicketCategory {
4
4
  id: string;
5
- projectId: string;
6
- sectionId: string;
5
+ internalTicketSectionId: string;
7
6
  name: string;
8
7
  color: string | null;
9
8
  description: string | null;
10
9
  order: number;
11
10
  isEnabled: boolean;
11
+ archivedAt: Date | null;
12
12
  createdAt?: Date;
13
13
  updatedAt?: Date;
14
14
  internalTicketSection?: IInternalTicketSection;
@@ -7,7 +7,6 @@ export interface IInternalTicketMessage {
7
7
  userId: string;
8
8
  content: string;
9
9
  replyToMessageId: string | null;
10
- mentionedUserIds: string[];
11
10
  createdAt?: Date;
12
11
  updatedAt?: Date;
13
12
  internalTicket?: IInternalTicket;
@@ -2,14 +2,16 @@ import { IInternalTicket } from './internal-ticket.model';
2
2
  import { IInternalTicketSection } from './internal-ticket-section.model';
3
3
  export interface IInternalTicketPriority {
4
4
  id: string;
5
- projectId: string;
6
- sectionId: string;
5
+ internalTicketSectionId: string;
7
6
  name: string;
8
- label: string | null;
9
7
  color: string | null;
8
+ description: string | null;
10
9
  level: number;
10
+ order: number;
11
11
  isDefault: boolean;
12
12
  isEnabled: boolean;
13
+ requirePriorityReason: boolean;
14
+ archivedAt: Date | null;
13
15
  createdAt?: Date;
14
16
  updatedAt?: Date;
15
17
  internalTicketSection?: IInternalTicketSection;
@@ -9,7 +9,7 @@ export interface IInternalTicketSection {
9
9
  color: string | null;
10
10
  icon: string | null;
11
11
  order: number;
12
- requirePriorityReason: boolean;
12
+ archivedAt: Date | null;
13
13
  createdAt?: Date;
14
14
  updatedAt?: Date;
15
15
  internalTicketCategory?: IInternalTicketCategory[];
@@ -10,12 +10,12 @@ import { IInternalTicketSection } from './internal-ticket-section.model';
10
10
  export interface IInternalTicket {
11
11
  id: string;
12
12
  projectId: string;
13
- sectionId: string;
13
+ internalTicketSectionId: string;
14
14
  title: string;
15
15
  description: string;
16
16
  status: InternalTicketStatus;
17
- priorityId: string | null;
18
- categoryId: string | null;
17
+ internalTicketPriorityId: string | null;
18
+ internalTicketCategoryId: string | null;
19
19
  createdByUserId: string;
20
20
  assignedToUserId: string | null;
21
21
  priorityCheckedAt: Date | null;
@@ -1,3 +1,4 @@
1
1
  export * from './error.utils';
2
2
  export * from './ip-address-validator.utils';
3
3
  export * from './cidr.util';
4
+ export * from './mention.utils';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./error.utils"), exports);
18
18
  __exportStar(require("./ip-address-validator.utils"), exports);
19
19
  __exportStar(require("./cidr.util"), exports);
20
+ __exportStar(require("./mention.utils"), exports);
@@ -0,0 +1,3 @@
1
+ export declare function extractMentionedUserIds(content: string): string[];
2
+ export declare function formatMentionsForDisplay(content: string): string;
3
+ export declare function hasMentions(content: string): boolean;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasMentions = exports.formatMentionsForDisplay = exports.extractMentionedUserIds = void 0;
4
+ function extractMentionedUserIds(content) {
5
+ const mentionRegex = /<@([a-f0-9-]+)\|[^>]+>/g;
6
+ const mentionedUserIds = [];
7
+ let match;
8
+ while ((match = mentionRegex.exec(content)) !== null) {
9
+ mentionedUserIds.push(match[1]);
10
+ }
11
+ return [...new Set(mentionedUserIds)];
12
+ }
13
+ exports.extractMentionedUserIds = extractMentionedUserIds;
14
+ function formatMentionsForDisplay(content) {
15
+ return content.replace(/<@[a-f0-9-]+\|([^>]+)>/g, '@$1');
16
+ }
17
+ exports.formatMentionsForDisplay = formatMentionsForDisplay;
18
+ function hasMentions(content) {
19
+ return /<@[a-f0-9-]+\|[^>]+>/.test(content);
20
+ }
21
+ exports.hasMentions = hasMentions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abyss-project/console",
3
- "version": "1.0.72",
3
+ "version": "1.0.75",
4
4
  "description": "Core package to interact with AbyssConsole",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,52 +0,0 @@
1
- export interface IReferenceResolver<T = any> {
2
- type: string;
3
- resolve: (id: string) => Promise<T> | T;
4
- }
5
- export interface IResolvedReference<T = any> {
6
- type: string;
7
- id: string;
8
- reference: string;
9
- value: T;
10
- resolvedValue: string;
11
- }
12
- export interface IValidationResult {
13
- valid: boolean;
14
- missingReferences: Array<{
15
- type: string;
16
- id: string;
17
- reference: string;
18
- }>;
19
- }
20
- export declare class ReferenceResolverUtils {
21
- private static resolvers;
22
- static registerResolver<T>(resolver: IReferenceResolver<T>): void;
23
- static unregisterResolver(type: string): void;
24
- static clearResolvers(): void;
25
- static hasReferences(value: string): boolean;
26
- static extractReferences(value: string): Array<{
27
- type: string;
28
- id: string;
29
- reference: string;
30
- }>;
31
- static extractReferencesFromArray(values: string[]): Array<{
32
- type: string;
33
- id: string;
34
- reference: string;
35
- }>;
36
- static extractReferencesFromObject(obj: any): Array<{
37
- type: string;
38
- id: string;
39
- reference: string;
40
- }>;
41
- private static uniqueReferences;
42
- static resolveString(value: string): Promise<string>;
43
- static resolveArray(values: string[]): Promise<string[]>;
44
- static resolveObject<T>(obj: T): Promise<T>;
45
- static validateReferences(value: any): Promise<IValidationResult>;
46
- static getResolutionInfo(value: string): Promise<IResolvedReference[]>;
47
- static resolveObjectWithTypes<T>(obj: T, types: string[]): Promise<T>;
48
- }
49
- export declare function resolveReferences<T>(value: T): Promise<T>;
50
- export declare function createResolver<T>(type: string, resolveFn: (id: string) => Promise<T> | T): IReferenceResolver<T>;
51
- export declare function createMapResolver<T>(type: string, map: Map<string, T>): IReferenceResolver<T>;
52
- export declare function createAsyncResolver<T>(type: string, fetchFn: (id: string) => Promise<T>): IReferenceResolver<T>;
@@ -1,219 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAsyncResolver = exports.createMapResolver = exports.createResolver = exports.resolveReferences = exports.ReferenceResolverUtils = void 0;
4
- const REFERENCE_PATTERN = /@(\w+):([a-zA-Z0-9-_]+)/g;
5
- class ReferenceResolverUtils {
6
- static registerResolver(resolver) {
7
- this.resolvers.set(resolver.type, resolver);
8
- }
9
- static unregisterResolver(type) {
10
- this.resolvers.delete(type);
11
- }
12
- static clearResolvers() {
13
- this.resolvers.clear();
14
- }
15
- static hasReferences(value) {
16
- const pattern = new RegExp(REFERENCE_PATTERN);
17
- return pattern.test(value);
18
- }
19
- static extractReferences(value) {
20
- const pattern = new RegExp(REFERENCE_PATTERN);
21
- const matches = value.matchAll(pattern);
22
- return Array.from(matches, (m) => ({
23
- type: m[1],
24
- id: m[2],
25
- reference: m[0],
26
- }));
27
- }
28
- static extractReferencesFromArray(values) {
29
- const allRefs = values.flatMap((value) => this.extractReferences(value));
30
- return this.uniqueReferences(allRefs);
31
- }
32
- static extractReferencesFromObject(obj) {
33
- const refs = [];
34
- const traverse = (value) => {
35
- if (typeof value === 'string' && this.hasReferences(value)) {
36
- refs.push(...this.extractReferences(value));
37
- }
38
- else if (Array.isArray(value)) {
39
- value.forEach(traverse);
40
- }
41
- else if (value && typeof value === 'object') {
42
- Object.values(value).forEach(traverse);
43
- }
44
- };
45
- traverse(obj);
46
- return this.uniqueReferences(refs);
47
- }
48
- static uniqueReferences(refs) {
49
- const seen = new Set();
50
- return refs.filter((ref) => {
51
- const key = `${ref.type}:${ref.id}`;
52
- if (seen.has(key))
53
- return false;
54
- seen.add(key);
55
- return true;
56
- });
57
- }
58
- static async resolveString(value) {
59
- const references = this.extractReferences(value);
60
- let resolved = value;
61
- for (const ref of references) {
62
- const resolver = this.resolvers.get(ref.type);
63
- if (!resolver) {
64
- throw new Error(`No resolver registered for type: ${ref.type}`);
65
- }
66
- const resolvedValue = await resolver.resolve(ref.id);
67
- if (resolvedValue === null || resolvedValue === undefined) {
68
- throw new Error(`Reference not found: ${ref.reference}`);
69
- }
70
- const stringValue = typeof resolvedValue === 'object'
71
- ? resolvedValue.value || JSON.stringify(resolvedValue)
72
- : String(resolvedValue);
73
- resolved = resolved.replace(ref.reference, stringValue);
74
- }
75
- return resolved;
76
- }
77
- static async resolveArray(values) {
78
- const resolved = await Promise.all(values.map(async (value) => {
79
- if (this.hasReferences(value)) {
80
- return await this.resolveString(value);
81
- }
82
- return value;
83
- }));
84
- return resolved.flat();
85
- }
86
- static async resolveObject(obj) {
87
- const resolve = async (value) => {
88
- if (typeof value === 'string' && this.hasReferences(value)) {
89
- return await this.resolveString(value);
90
- }
91
- else if (Array.isArray(value)) {
92
- return await Promise.all(value.map(resolve));
93
- }
94
- else if (value && typeof value === 'object') {
95
- const resolved = {};
96
- for (const [key, val] of Object.entries(value)) {
97
- resolved[key] = await resolve(val);
98
- }
99
- return resolved;
100
- }
101
- return value;
102
- };
103
- return await resolve(obj);
104
- }
105
- static async validateReferences(value) {
106
- const references = typeof value === 'string'
107
- ? this.extractReferences(value)
108
- : this.extractReferencesFromObject(value);
109
- const missingReferences = [];
110
- for (const ref of references) {
111
- const resolver = this.resolvers.get(ref.type);
112
- if (!resolver) {
113
- missingReferences.push(ref);
114
- continue;
115
- }
116
- try {
117
- const resolved = await resolver.resolve(ref.id);
118
- if (resolved === null || resolved === undefined) {
119
- missingReferences.push(ref);
120
- }
121
- }
122
- catch {
123
- missingReferences.push(ref);
124
- }
125
- }
126
- return {
127
- valid: missingReferences.length === 0,
128
- missingReferences,
129
- };
130
- }
131
- static async getResolutionInfo(value) {
132
- const references = this.extractReferences(value);
133
- const results = [];
134
- for (const ref of references) {
135
- const resolver = this.resolvers.get(ref.type);
136
- if (!resolver) {
137
- throw new Error(`No resolver registered for type: ${ref.type}`);
138
- }
139
- const resolvedValue = await resolver.resolve(ref.id);
140
- if (resolvedValue === null || resolvedValue === undefined) {
141
- throw new Error(`Reference not found: ${ref.reference}`);
142
- }
143
- const stringValue = typeof resolvedValue === 'object'
144
- ? resolvedValue.value || JSON.stringify(resolvedValue)
145
- : String(resolvedValue);
146
- results.push({
147
- type: ref.type,
148
- id: ref.id,
149
- reference: ref.reference,
150
- value: resolvedValue,
151
- resolvedValue: stringValue,
152
- });
153
- }
154
- return results;
155
- }
156
- static async resolveObjectWithTypes(obj, types) {
157
- const typeSet = new Set(types);
158
- const resolve = async (value) => {
159
- if (typeof value === 'string' && this.hasReferences(value)) {
160
- const references = this.extractReferences(value);
161
- let resolved = value;
162
- for (const ref of references) {
163
- if (!typeSet.has(ref.type))
164
- continue;
165
- const resolver = this.resolvers.get(ref.type);
166
- if (!resolver)
167
- continue;
168
- const resolvedValue = await resolver.resolve(ref.id);
169
- if (resolvedValue === null || resolvedValue === undefined)
170
- continue;
171
- const stringValue = typeof resolvedValue === 'object'
172
- ? resolvedValue.value || JSON.stringify(resolvedValue)
173
- : String(resolvedValue);
174
- resolved = resolved.replace(ref.reference, stringValue);
175
- }
176
- return resolved;
177
- }
178
- else if (Array.isArray(value)) {
179
- return await Promise.all(value.map(resolve));
180
- }
181
- else if (value && typeof value === 'object') {
182
- const resolved = {};
183
- for (const [key, val] of Object.entries(value)) {
184
- resolved[key] = await resolve(val);
185
- }
186
- return resolved;
187
- }
188
- return value;
189
- };
190
- return await resolve(obj);
191
- }
192
- }
193
- exports.ReferenceResolverUtils = ReferenceResolverUtils;
194
- ReferenceResolverUtils.resolvers = new Map();
195
- async function resolveReferences(value) {
196
- return ReferenceResolverUtils.resolveObject(value);
197
- }
198
- exports.resolveReferences = resolveReferences;
199
- function createResolver(type, resolveFn) {
200
- return {
201
- type,
202
- resolve: resolveFn,
203
- };
204
- }
205
- exports.createResolver = createResolver;
206
- function createMapResolver(type, map) {
207
- return createResolver(type, (id) => {
208
- const value = map.get(id);
209
- if (value === undefined) {
210
- throw new Error(`${type} not found: ${id}`);
211
- }
212
- return value;
213
- });
214
- }
215
- exports.createMapResolver = createMapResolver;
216
- function createAsyncResolver(type, fetchFn) {
217
- return createResolver(type, fetchFn);
218
- }
219
- exports.createAsyncResolver = createAsyncResolver;