@okf/ootils 1.3.4 → 1.3.5

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.
@@ -31,4 +31,98 @@ interface RichTextValue {
31
31
  type TagNameInput = string | number | RichTextValue | null | undefined;
32
32
  declare const genTagId: (tagName: TagNameInput) => string;
33
33
 
34
- export { deleteVal, genTagId, getVal, setVal };
34
+ /**
35
+ * Converts a value to an array, ensuring the result is always an array type.
36
+ *
37
+ * This utility function normalizes input values by:
38
+ * - Returning the input unchanged if it's already an array
39
+ * - Wrapping single values in an array
40
+ * - Preserving meaningful falsy values (false, 0) by wrapping them in arrays
41
+ * - Converting other falsy values (null, undefined, empty string) to empty arrays
42
+ *
43
+ * @template T - The type of the input value(s)
44
+ * @param {T | T[] | null | undefined | false | 0} property - The value to convert to an array
45
+ * @returns {T[]} An array containing the input value(s)
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * toArray("hello") // ["hello"]
50
+ * toArray(["a", "b"]) // ["a", "b"] (unchanged)
51
+ * toArray(42) // [42]
52
+ * toArray(false) // [false] (preserved)
53
+ * toArray(0) // [0] (preserved)
54
+ * toArray(null) // []
55
+ * toArray(undefined) // []
56
+ * toArray("") // []
57
+ * ```
58
+ */
59
+ declare const toArray: <T>(property: T | T[] | null | undefined | false | 0) => T[];
60
+
61
+ interface Block {
62
+ [key: string]: any;
63
+ comp?: string;
64
+ valuePath?: string;
65
+ blocks?: Block[];
66
+ }
67
+ interface ExtractedBlock extends Block {
68
+ sectionStack: Section[];
69
+ blockPath: string;
70
+ }
71
+ interface Section {
72
+ [key: string]: any;
73
+ blocks?: Block[];
74
+ }
75
+ interface Template {
76
+ category: string;
77
+ kp_templates?: {
78
+ [spaceId: string]: SpaceConfig;
79
+ } & {
80
+ myProfileConfig?: Block[];
81
+ };
82
+ kp_settings?: Block[];
83
+ }
84
+ interface SpaceConfig {
85
+ builder?: 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
86
+ configs?: Block[] | {
87
+ inputs: {
88
+ [key: string]: Block;
89
+ };
90
+ };
91
+ subSpaces?: SpaceConfig[];
92
+ }
93
+ type BuilderType = 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
94
+ /**
95
+ * Extracts all blocks from a template configuration, preserving their hierarchical context.
96
+ *
97
+ * This function traverses template structures and extracts individual block configurations
98
+ * while maintaining information about their location (blockPath) and parent sections
99
+ * (sectionStack). This metadata is crucial for:
100
+ * - Updating block properties at their exact location
101
+ * - Handling display conditions that affect entire sections
102
+ * - Managing nested block hierarchies in form builders
103
+ *
104
+ * @param {Object} params - Extraction parameters
105
+ * @param {Template} params.tpl - The template configuration to extract blocks from
106
+ * @param {BuilderType[]} [params.buildersWhitelist] - Optional list of builders to extract from.
107
+ * If provided, only blocks from these builders will be included
108
+ * @returns {ExtractedBlock[]} Array of blocks with added sectionStack and blockPath metadata
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const blocks = extractAllBlocksFromTpl({
113
+ * tpl: templateConfig,
114
+ * buildersWhitelist: ['FormBuilder', 'kp_settings']
115
+ * });
116
+ *
117
+ * // Each block will have:
118
+ * // - Original block properties (type, label, valuePath, etc.)
119
+ * // - sectionStack: Array of parent sections for display condition handling
120
+ * // - blockPath: Dot-notation path for precise updates (e.g., "kp_templates.header.configs.0")
121
+ * ```
122
+ */
123
+ declare const extractAllBlocksFromTpl: ({ tpl, buildersWhitelist }: {
124
+ tpl: Template;
125
+ buildersWhitelist?: BuilderType[];
126
+ }) => ExtractedBlock[];
127
+
128
+ export { deleteVal, extractAllBlocksFromTpl, genTagId, getVal, setVal, toArray };
package/dist/browser.d.ts CHANGED
@@ -31,4 +31,98 @@ interface RichTextValue {
31
31
  type TagNameInput = string | number | RichTextValue | null | undefined;
32
32
  declare const genTagId: (tagName: TagNameInput) => string;
33
33
 
34
- export { deleteVal, genTagId, getVal, setVal };
34
+ /**
35
+ * Converts a value to an array, ensuring the result is always an array type.
36
+ *
37
+ * This utility function normalizes input values by:
38
+ * - Returning the input unchanged if it's already an array
39
+ * - Wrapping single values in an array
40
+ * - Preserving meaningful falsy values (false, 0) by wrapping them in arrays
41
+ * - Converting other falsy values (null, undefined, empty string) to empty arrays
42
+ *
43
+ * @template T - The type of the input value(s)
44
+ * @param {T | T[] | null | undefined | false | 0} property - The value to convert to an array
45
+ * @returns {T[]} An array containing the input value(s)
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * toArray("hello") // ["hello"]
50
+ * toArray(["a", "b"]) // ["a", "b"] (unchanged)
51
+ * toArray(42) // [42]
52
+ * toArray(false) // [false] (preserved)
53
+ * toArray(0) // [0] (preserved)
54
+ * toArray(null) // []
55
+ * toArray(undefined) // []
56
+ * toArray("") // []
57
+ * ```
58
+ */
59
+ declare const toArray: <T>(property: T | T[] | null | undefined | false | 0) => T[];
60
+
61
+ interface Block {
62
+ [key: string]: any;
63
+ comp?: string;
64
+ valuePath?: string;
65
+ blocks?: Block[];
66
+ }
67
+ interface ExtractedBlock extends Block {
68
+ sectionStack: Section[];
69
+ blockPath: string;
70
+ }
71
+ interface Section {
72
+ [key: string]: any;
73
+ blocks?: Block[];
74
+ }
75
+ interface Template {
76
+ category: string;
77
+ kp_templates?: {
78
+ [spaceId: string]: SpaceConfig;
79
+ } & {
80
+ myProfileConfig?: Block[];
81
+ };
82
+ kp_settings?: Block[];
83
+ }
84
+ interface SpaceConfig {
85
+ builder?: 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
86
+ configs?: Block[] | {
87
+ inputs: {
88
+ [key: string]: Block;
89
+ };
90
+ };
91
+ subSpaces?: SpaceConfig[];
92
+ }
93
+ type BuilderType = 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
94
+ /**
95
+ * Extracts all blocks from a template configuration, preserving their hierarchical context.
96
+ *
97
+ * This function traverses template structures and extracts individual block configurations
98
+ * while maintaining information about their location (blockPath) and parent sections
99
+ * (sectionStack). This metadata is crucial for:
100
+ * - Updating block properties at their exact location
101
+ * - Handling display conditions that affect entire sections
102
+ * - Managing nested block hierarchies in form builders
103
+ *
104
+ * @param {Object} params - Extraction parameters
105
+ * @param {Template} params.tpl - The template configuration to extract blocks from
106
+ * @param {BuilderType[]} [params.buildersWhitelist] - Optional list of builders to extract from.
107
+ * If provided, only blocks from these builders will be included
108
+ * @returns {ExtractedBlock[]} Array of blocks with added sectionStack and blockPath metadata
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const blocks = extractAllBlocksFromTpl({
113
+ * tpl: templateConfig,
114
+ * buildersWhitelist: ['FormBuilder', 'kp_settings']
115
+ * });
116
+ *
117
+ * // Each block will have:
118
+ * // - Original block properties (type, label, valuePath, etc.)
119
+ * // - sectionStack: Array of parent sections for display condition handling
120
+ * // - blockPath: Dot-notation path for precise updates (e.g., "kp_templates.header.configs.0")
121
+ * ```
122
+ */
123
+ declare const extractAllBlocksFromTpl: ({ tpl, buildersWhitelist }: {
124
+ tpl: Template;
125
+ buildersWhitelist?: BuilderType[];
126
+ }) => ExtractedBlock[];
127
+
128
+ export { deleteVal, extractAllBlocksFromTpl, genTagId, getVal, setVal, toArray };
package/dist/browser.js CHANGED
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var browser_exports = {};
22
22
  __export(browser_exports, {
23
23
  deleteVal: () => deleteVal,
24
+ extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
24
25
  genTagId: () => genTagId,
25
26
  getVal: () => getVal,
26
- setVal: () => setVal
27
+ setVal: () => setVal,
28
+ toArray: () => toArray
27
29
  });
28
30
  module.exports = __toCommonJS(browser_exports);
29
31
 
@@ -182,10 +184,131 @@ var genTagId = (tagName) => {
182
184
  toReturn = toReturn.replace(/\+/g, "plus");
183
185
  return toReturn.replace(/^_+|_+$/, "");
184
186
  };
187
+
188
+ // src/utils/toArray.ts
189
+ var toArray = (property) => {
190
+ if (!property && (property !== false && property !== 0)) return [];
191
+ if (Array.isArray(property)) return property;
192
+ return [property];
193
+ };
194
+
195
+ // src/utils/extractAllBlocksFromTpl.ts
196
+ var extractAllBlocksFromTpl = ({
197
+ tpl,
198
+ buildersWhitelist
199
+ }) => {
200
+ if (tpl.category === "userProfiles") {
201
+ const allBlocksAry = [];
202
+ if (tpl.kp_templates?.myProfileConfig) {
203
+ _recursExtractBlocks({
204
+ data: tpl.kp_templates.myProfileConfig,
205
+ cb: (block) => allBlocksAry.push(block),
206
+ sectionStack: [],
207
+ blockPathPrefix: "kp_templates.myProfileConfig"
208
+ });
209
+ }
210
+ return allBlocksAry;
211
+ } else {
212
+ return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
213
+ }
214
+ };
215
+ var _recursExtractBlocks = ({
216
+ data,
217
+ cb,
218
+ sectionStack = [],
219
+ blockPathPrefix = ""
220
+ }) => {
221
+ data.forEach((d, idx) => {
222
+ if (!d.blocks) {
223
+ cb({
224
+ ...d,
225
+ sectionStack,
226
+ blockPath: `${blockPathPrefix}.${idx}`
227
+ });
228
+ } else {
229
+ _recursExtractBlocks({
230
+ data: d.blocks,
231
+ cb,
232
+ sectionStack: [...sectionStack, d],
233
+ blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
234
+ });
235
+ }
236
+ });
237
+ };
238
+ var extractAllBlocksFromStructuredTpls = ({
239
+ tpl,
240
+ buildersWhitelist
241
+ }) => {
242
+ const allBlocksAry = [];
243
+ if (tpl.kp_templates) {
244
+ for (let spaceId in tpl.kp_templates) {
245
+ let conf = tpl.kp_templates[spaceId];
246
+ if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
247
+ continue;
248
+ }
249
+ if (!conf.subSpaces) {
250
+ _extractBlocksFromSomeBuilders({
251
+ conf,
252
+ confPath: `kp_templates.${spaceId}`,
253
+ allBlocksAry
254
+ });
255
+ } else {
256
+ conf.subSpaces.forEach((sub, subIdx) => {
257
+ if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
258
+ return;
259
+ }
260
+ _extractBlocksFromSomeBuilders({
261
+ conf: sub,
262
+ confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
263
+ allBlocksAry
264
+ });
265
+ });
266
+ }
267
+ }
268
+ }
269
+ if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
270
+ return allBlocksAry;
271
+ }
272
+ if (tpl.kp_settings && tpl.kp_settings.length > 0) {
273
+ _recursExtractBlocks({
274
+ data: tpl.kp_settings,
275
+ cb: (block) => allBlocksAry.push(block),
276
+ blockPathPrefix: "kp_settings"
277
+ });
278
+ }
279
+ return allBlocksAry;
280
+ };
281
+ var _extractBlocksFromSomeBuilders = ({
282
+ conf,
283
+ confPath,
284
+ allBlocksAry
285
+ }) => {
286
+ if (conf.builder === "FormBuilder") {
287
+ const configs = conf.configs || [];
288
+ _recursExtractBlocks({
289
+ data: configs,
290
+ cb: (block) => allBlocksAry.push(block),
291
+ blockPathPrefix: `${confPath}.configs`
292
+ });
293
+ }
294
+ if (conf.builder === "MetaBuilder") {
295
+ const inputs = conf.configs?.inputs || {};
296
+ const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
297
+ const value = inputs[inputBlockKey];
298
+ return {
299
+ ...value,
300
+ blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
301
+ };
302
+ });
303
+ allBlocksAry.push(...inputBlockConfigsToPush);
304
+ }
305
+ };
185
306
  // Annotate the CommonJS export names for ESM import in node:
186
307
  0 && (module.exports = {
187
308
  deleteVal,
309
+ extractAllBlocksFromTpl,
188
310
  genTagId,
189
311
  getVal,
190
- setVal
312
+ setVal,
313
+ toArray
191
314
  });
package/dist/browser.mjs CHANGED
@@ -153,9 +153,130 @@ var genTagId = (tagName) => {
153
153
  toReturn = toReturn.replace(/\+/g, "plus");
154
154
  return toReturn.replace(/^_+|_+$/, "");
155
155
  };
156
+
157
+ // src/utils/toArray.ts
158
+ var toArray = (property) => {
159
+ if (!property && (property !== false && property !== 0)) return [];
160
+ if (Array.isArray(property)) return property;
161
+ return [property];
162
+ };
163
+
164
+ // src/utils/extractAllBlocksFromTpl.ts
165
+ var extractAllBlocksFromTpl = ({
166
+ tpl,
167
+ buildersWhitelist
168
+ }) => {
169
+ if (tpl.category === "userProfiles") {
170
+ const allBlocksAry = [];
171
+ if (tpl.kp_templates?.myProfileConfig) {
172
+ _recursExtractBlocks({
173
+ data: tpl.kp_templates.myProfileConfig,
174
+ cb: (block) => allBlocksAry.push(block),
175
+ sectionStack: [],
176
+ blockPathPrefix: "kp_templates.myProfileConfig"
177
+ });
178
+ }
179
+ return allBlocksAry;
180
+ } else {
181
+ return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
182
+ }
183
+ };
184
+ var _recursExtractBlocks = ({
185
+ data,
186
+ cb,
187
+ sectionStack = [],
188
+ blockPathPrefix = ""
189
+ }) => {
190
+ data.forEach((d, idx) => {
191
+ if (!d.blocks) {
192
+ cb({
193
+ ...d,
194
+ sectionStack,
195
+ blockPath: `${blockPathPrefix}.${idx}`
196
+ });
197
+ } else {
198
+ _recursExtractBlocks({
199
+ data: d.blocks,
200
+ cb,
201
+ sectionStack: [...sectionStack, d],
202
+ blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
203
+ });
204
+ }
205
+ });
206
+ };
207
+ var extractAllBlocksFromStructuredTpls = ({
208
+ tpl,
209
+ buildersWhitelist
210
+ }) => {
211
+ const allBlocksAry = [];
212
+ if (tpl.kp_templates) {
213
+ for (let spaceId in tpl.kp_templates) {
214
+ let conf = tpl.kp_templates[spaceId];
215
+ if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
216
+ continue;
217
+ }
218
+ if (!conf.subSpaces) {
219
+ _extractBlocksFromSomeBuilders({
220
+ conf,
221
+ confPath: `kp_templates.${spaceId}`,
222
+ allBlocksAry
223
+ });
224
+ } else {
225
+ conf.subSpaces.forEach((sub, subIdx) => {
226
+ if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
227
+ return;
228
+ }
229
+ _extractBlocksFromSomeBuilders({
230
+ conf: sub,
231
+ confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
232
+ allBlocksAry
233
+ });
234
+ });
235
+ }
236
+ }
237
+ }
238
+ if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
239
+ return allBlocksAry;
240
+ }
241
+ if (tpl.kp_settings && tpl.kp_settings.length > 0) {
242
+ _recursExtractBlocks({
243
+ data: tpl.kp_settings,
244
+ cb: (block) => allBlocksAry.push(block),
245
+ blockPathPrefix: "kp_settings"
246
+ });
247
+ }
248
+ return allBlocksAry;
249
+ };
250
+ var _extractBlocksFromSomeBuilders = ({
251
+ conf,
252
+ confPath,
253
+ allBlocksAry
254
+ }) => {
255
+ if (conf.builder === "FormBuilder") {
256
+ const configs = conf.configs || [];
257
+ _recursExtractBlocks({
258
+ data: configs,
259
+ cb: (block) => allBlocksAry.push(block),
260
+ blockPathPrefix: `${confPath}.configs`
261
+ });
262
+ }
263
+ if (conf.builder === "MetaBuilder") {
264
+ const inputs = conf.configs?.inputs || {};
265
+ const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
266
+ const value = inputs[inputBlockKey];
267
+ return {
268
+ ...value,
269
+ blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
270
+ };
271
+ });
272
+ allBlocksAry.push(...inputBlockConfigsToPush);
273
+ }
274
+ };
156
275
  export {
157
276
  deleteVal,
277
+ extractAllBlocksFromTpl,
158
278
  genTagId,
159
279
  getVal,
160
- setVal
280
+ setVal,
281
+ toArray
161
282
  };
package/dist/node.d.mts CHANGED
@@ -34,6 +34,100 @@ interface RichTextValue {
34
34
  type TagNameInput = string | number | RichTextValue | null | undefined;
35
35
  declare const genTagId: (tagName: TagNameInput) => string;
36
36
 
37
+ /**
38
+ * Converts a value to an array, ensuring the result is always an array type.
39
+ *
40
+ * This utility function normalizes input values by:
41
+ * - Returning the input unchanged if it's already an array
42
+ * - Wrapping single values in an array
43
+ * - Preserving meaningful falsy values (false, 0) by wrapping them in arrays
44
+ * - Converting other falsy values (null, undefined, empty string) to empty arrays
45
+ *
46
+ * @template T - The type of the input value(s)
47
+ * @param {T | T[] | null | undefined | false | 0} property - The value to convert to an array
48
+ * @returns {T[]} An array containing the input value(s)
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * toArray("hello") // ["hello"]
53
+ * toArray(["a", "b"]) // ["a", "b"] (unchanged)
54
+ * toArray(42) // [42]
55
+ * toArray(false) // [false] (preserved)
56
+ * toArray(0) // [0] (preserved)
57
+ * toArray(null) // []
58
+ * toArray(undefined) // []
59
+ * toArray("") // []
60
+ * ```
61
+ */
62
+ declare const toArray: <T>(property: T | T[] | null | undefined | false | 0) => T[];
63
+
64
+ interface Block {
65
+ [key: string]: any;
66
+ comp?: string;
67
+ valuePath?: string;
68
+ blocks?: Block[];
69
+ }
70
+ interface ExtractedBlock extends Block {
71
+ sectionStack: Section[];
72
+ blockPath: string;
73
+ }
74
+ interface Section {
75
+ [key: string]: any;
76
+ blocks?: Block[];
77
+ }
78
+ interface Template$1 {
79
+ category: string;
80
+ kp_templates?: {
81
+ [spaceId: string]: SpaceConfig;
82
+ } & {
83
+ myProfileConfig?: Block[];
84
+ };
85
+ kp_settings?: Block[];
86
+ }
87
+ interface SpaceConfig {
88
+ builder?: 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
89
+ configs?: Block[] | {
90
+ inputs: {
91
+ [key: string]: Block;
92
+ };
93
+ };
94
+ subSpaces?: SpaceConfig[];
95
+ }
96
+ type BuilderType = 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
97
+ /**
98
+ * Extracts all blocks from a template configuration, preserving their hierarchical context.
99
+ *
100
+ * This function traverses template structures and extracts individual block configurations
101
+ * while maintaining information about their location (blockPath) and parent sections
102
+ * (sectionStack). This metadata is crucial for:
103
+ * - Updating block properties at their exact location
104
+ * - Handling display conditions that affect entire sections
105
+ * - Managing nested block hierarchies in form builders
106
+ *
107
+ * @param {Object} params - Extraction parameters
108
+ * @param {Template} params.tpl - The template configuration to extract blocks from
109
+ * @param {BuilderType[]} [params.buildersWhitelist] - Optional list of builders to extract from.
110
+ * If provided, only blocks from these builders will be included
111
+ * @returns {ExtractedBlock[]} Array of blocks with added sectionStack and blockPath metadata
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const blocks = extractAllBlocksFromTpl({
116
+ * tpl: templateConfig,
117
+ * buildersWhitelist: ['FormBuilder', 'kp_settings']
118
+ * });
119
+ *
120
+ * // Each block will have:
121
+ * // - Original block properties (type, label, valuePath, etc.)
122
+ * // - sectionStack: Array of parent sections for display condition handling
123
+ * // - blockPath: Dot-notation path for precise updates (e.g., "kp_templates.header.configs.0")
124
+ * ```
125
+ */
126
+ declare const extractAllBlocksFromTpl: ({ tpl, buildersWhitelist }: {
127
+ tpl: Template$1;
128
+ buildersWhitelist?: BuilderType[];
129
+ }) => ExtractedBlock[];
130
+
37
131
  interface DbConnections {
38
132
  [clusterName: string]: Connection;
39
133
  }
@@ -175,4 +269,4 @@ declare const getAIConfigs: ({ tenant }: GetAIConfigsParams) => Promise<AIconfig
175
269
  declare const connectToRedis: () => Promise<void>;
176
270
  declare const getRedisClient: () => IORedis;
177
271
 
178
- export { connectToRedis, deleteVal, genTagId, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, updateGlobalConfig };
272
+ export { connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, toArray, updateGlobalConfig };
package/dist/node.d.ts CHANGED
@@ -34,6 +34,100 @@ interface RichTextValue {
34
34
  type TagNameInput = string | number | RichTextValue | null | undefined;
35
35
  declare const genTagId: (tagName: TagNameInput) => string;
36
36
 
37
+ /**
38
+ * Converts a value to an array, ensuring the result is always an array type.
39
+ *
40
+ * This utility function normalizes input values by:
41
+ * - Returning the input unchanged if it's already an array
42
+ * - Wrapping single values in an array
43
+ * - Preserving meaningful falsy values (false, 0) by wrapping them in arrays
44
+ * - Converting other falsy values (null, undefined, empty string) to empty arrays
45
+ *
46
+ * @template T - The type of the input value(s)
47
+ * @param {T | T[] | null | undefined | false | 0} property - The value to convert to an array
48
+ * @returns {T[]} An array containing the input value(s)
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * toArray("hello") // ["hello"]
53
+ * toArray(["a", "b"]) // ["a", "b"] (unchanged)
54
+ * toArray(42) // [42]
55
+ * toArray(false) // [false] (preserved)
56
+ * toArray(0) // [0] (preserved)
57
+ * toArray(null) // []
58
+ * toArray(undefined) // []
59
+ * toArray("") // []
60
+ * ```
61
+ */
62
+ declare const toArray: <T>(property: T | T[] | null | undefined | false | 0) => T[];
63
+
64
+ interface Block {
65
+ [key: string]: any;
66
+ comp?: string;
67
+ valuePath?: string;
68
+ blocks?: Block[];
69
+ }
70
+ interface ExtractedBlock extends Block {
71
+ sectionStack: Section[];
72
+ blockPath: string;
73
+ }
74
+ interface Section {
75
+ [key: string]: any;
76
+ blocks?: Block[];
77
+ }
78
+ interface Template$1 {
79
+ category: string;
80
+ kp_templates?: {
81
+ [spaceId: string]: SpaceConfig;
82
+ } & {
83
+ myProfileConfig?: Block[];
84
+ };
85
+ kp_settings?: Block[];
86
+ }
87
+ interface SpaceConfig {
88
+ builder?: 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
89
+ configs?: Block[] | {
90
+ inputs: {
91
+ [key: string]: Block;
92
+ };
93
+ };
94
+ subSpaces?: SpaceConfig[];
95
+ }
96
+ type BuilderType = 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
97
+ /**
98
+ * Extracts all blocks from a template configuration, preserving their hierarchical context.
99
+ *
100
+ * This function traverses template structures and extracts individual block configurations
101
+ * while maintaining information about their location (blockPath) and parent sections
102
+ * (sectionStack). This metadata is crucial for:
103
+ * - Updating block properties at their exact location
104
+ * - Handling display conditions that affect entire sections
105
+ * - Managing nested block hierarchies in form builders
106
+ *
107
+ * @param {Object} params - Extraction parameters
108
+ * @param {Template} params.tpl - The template configuration to extract blocks from
109
+ * @param {BuilderType[]} [params.buildersWhitelist] - Optional list of builders to extract from.
110
+ * If provided, only blocks from these builders will be included
111
+ * @returns {ExtractedBlock[]} Array of blocks with added sectionStack and blockPath metadata
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const blocks = extractAllBlocksFromTpl({
116
+ * tpl: templateConfig,
117
+ * buildersWhitelist: ['FormBuilder', 'kp_settings']
118
+ * });
119
+ *
120
+ * // Each block will have:
121
+ * // - Original block properties (type, label, valuePath, etc.)
122
+ * // - sectionStack: Array of parent sections for display condition handling
123
+ * // - blockPath: Dot-notation path for precise updates (e.g., "kp_templates.header.configs.0")
124
+ * ```
125
+ */
126
+ declare const extractAllBlocksFromTpl: ({ tpl, buildersWhitelist }: {
127
+ tpl: Template$1;
128
+ buildersWhitelist?: BuilderType[];
129
+ }) => ExtractedBlock[];
130
+
37
131
  interface DbConnections {
38
132
  [clusterName: string]: Connection;
39
133
  }
@@ -175,4 +269,4 @@ declare const getAIConfigs: ({ tenant }: GetAIConfigsParams) => Promise<AIconfig
175
269
  declare const connectToRedis: () => Promise<void>;
176
270
  declare const getRedisClient: () => IORedis;
177
271
 
178
- export { connectToRedis, deleteVal, genTagId, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, updateGlobalConfig };
272
+ export { connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, toArray, updateGlobalConfig };