@blocksdiy/blocks-client-sdk 1.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.
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Base entity properties automatically included in all entity instances
3
+ * These system fields are managed by the backend and available on all entities
4
+ * @interface BaseEntityType
5
+ */
6
+ export interface BaseEntityType {
7
+ /** Unique identifier for the entity */
8
+ id: string;
9
+ /** ISO timestamp of when the entity was created */
10
+ createdAt: string;
11
+ /** ISO timestamp of when the entity was last updated */
12
+ updatedAt: string;
13
+ /** ID of the user who created the entity */
14
+ createdBy: string;
15
+ /** ID of the user who last updated the entity */
16
+ updatedBy: string;
17
+ /** ID of the agent that last updated the entity (if applicable) */
18
+ updatedByAgentId: string;
19
+ }
20
+ /**
21
+ * Configuration for defining an entity type
22
+ *
23
+ * This interface is used to define the structure and mapping of an entity,
24
+ * connecting frontend property names to database column names.
25
+ *
26
+ * @interface EntityConfig
27
+ * @template T - Type defining the structure of the entity instance
28
+ * @property {string} tableBlockId - Unique identifier for the table where the entity is stored
29
+ * @property {T} instanceType - Type definition object for the entity's structure
30
+ */
31
+ export interface EntityConfig<T extends Record<string, unknown> = {}> {
32
+ tableBlockId: string;
33
+ instanceType: T;
34
+ }
35
+ /**
36
+ * Type representing only the mutable fields of an entity
37
+ * Used for creating or updating entities with user-defined fields only
38
+ */
39
+ export type EntityTypeOnlyMutable<E extends EntityConfig> = E["instanceType"];
40
+ /**
41
+ * Type representing the complete entity with system and user-defined fields
42
+ * This is the standard format used in the frontend application
43
+ */
44
+ export type EntityType<E extends EntityConfig> = BaseEntityType & EntityTypeOnlyMutable<E>;
45
+ /**
46
+ * Entity class for performing CRUD operations on data entities
47
+ *
48
+ * This class provides methods to create, read, update, and delete entity records,
49
+ * handling the mapping between frontend property names and database column names.
50
+ *
51
+ * @class Entity
52
+ * @template EC - Entity configuration type
53
+ */
54
+ export declare class Entity<EC extends EntityConfig = EntityConfig> {
55
+ private tableBlockId;
56
+ private dataApiService;
57
+ /**
58
+ * Creates a new Entity instance
59
+ * @param {EC} config - Configuration for the entity
60
+ * @param {string} token - The token for the application
61
+ */
62
+ constructor(config: EC, { token }?: {
63
+ token?: string;
64
+ });
65
+ /**
66
+ * Retrieves a single entity by filters
67
+ *
68
+ * Fetches an entity from the database and transforms it to the frontend format
69
+ * with properly mapped property names.
70
+ *
71
+ * @param {Record<string, any>} filters - Filters to identify the entity (e.g., { id: "123" } or { email: "user@example.com" })
72
+ * @returns {Promise<EntityType<EC> | null>} The entity if found, null otherwise
73
+ * @example
74
+ * ```ts
75
+ * // Define a user entity configuration
76
+ * const userConfig = {
77
+ * tableBlockId: 'users-table',
78
+ * instanceType: {} as {
79
+ * name: string;
80
+ * email: string;
81
+ * }
82
+ * };
83
+ *
84
+ * // Create entity instance
85
+ * const userEntity = new Entity(userConfig);
86
+ *
87
+ * // Find a user by email
88
+ * const user = await userEntity.findOne({ email: 'user@example.com' });
89
+ * if (user) {
90
+ * console.log(`Found user: ${user.name}, email: ${user.email}`);
91
+ * }
92
+ * ```
93
+ */
94
+ findOne(filters: Record<string, any>): Promise<EntityType<EC> | null>;
95
+ /**
96
+ * Retrieves multiple entities that match the provided filters
97
+ *
98
+ * Fetches entities from the database and transforms them to the frontend format
99
+ * with properly mapped property names.
100
+ *
101
+ * @param {any} [filters] - Optional filters to apply to the query
102
+ * @returns {Promise<Array<EntityType<EC>>>} Array of matching entities
103
+ * @example
104
+ * ```ts
105
+ * // Define a product entity configuration
106
+ * const productConfig = {
107
+ * tableBlockId: 'products-table',
108
+ * instanceType: {} as {
109
+ * name: string;
110
+ * price: number;
111
+ * category: string;
112
+ * }
113
+ * };
114
+ *
115
+ * // Create entity instance
116
+ * const productEntity = new Entity(productConfig);
117
+ *
118
+ * // Find all products in a specific category
119
+ * const products = await productEntity.findMany({ category: 'electronics' });
120
+ *
121
+ * // Process the results
122
+ * products.forEach(product => {
123
+ * console.log(`${product.name}: $${product.price}`);
124
+ * });
125
+ * ```
126
+ */
127
+ findMany(filters?: any): Promise<any[]>;
128
+ /**
129
+ * Creates a new entity in the database
130
+ *
131
+ * Transforms the provided data to the database format with column name mapping
132
+ * and inserts it into the database.
133
+ *
134
+ * @param {EntityTypeOnlyMutable<EC>} data - The entity data to create
135
+ * @returns {Promise<EntityType<EC>>} The created entity with system fields
136
+ * @example
137
+ * ```ts
138
+ * // Define a task entity configuration
139
+ * const taskConfig = {
140
+ * tableBlockId: 'tasks-table',
141
+ * instanceType: {} as {
142
+ * title: string;
143
+ * description: string;
144
+ * status: 'todo' | 'in_progress' | 'done';
145
+ * assigneeId: string;
146
+ * }
147
+ * };
148
+ *
149
+ * // Create entity instance
150
+ * const taskEntity = new Entity(taskConfig);
151
+ *
152
+ * // Create a new task
153
+ * const newTask = await taskEntity.create({
154
+ * title: 'Implement feature X',
155
+ * description: 'Add the new feature with tests',
156
+ * status: 'todo',
157
+ * assigneeId: 'user-456'
158
+ * });
159
+ *
160
+ * console.log(`Created task with ID: ${newTask.id}`);
161
+ * ```
162
+ */
163
+ create(data: EntityTypeOnlyMutable<EC>): Promise<EntityType<EC>>;
164
+ /**
165
+ * Creates multiple new entities in the database
166
+ *
167
+ * Transforms the provided array of data to the database format with column name mapping
168
+ * and inserts them into the database in a single operation.
169
+ *
170
+ * @param {EntityTypeOnlyMutable<EC>[]} data - Array of entity data to create
171
+ * @returns {Promise<EntityType<EC>[]>} Array of created entities with system fields
172
+ * @example
173
+ * ```ts
174
+ * // Define a task entity configuration
175
+ * const taskConfig = {
176
+ * tableBlockId: 'tasks-table',
177
+ * instanceType: {} as {
178
+ * title: string;
179
+ * description: string;
180
+ * status: 'todo' | 'in_progress' | 'done';
181
+ * assigneeId: string;
182
+ * }
183
+ * };
184
+ *
185
+ * // Create entity instance
186
+ * const taskEntity = new Entity(taskConfig);
187
+ *
188
+ * // Create multiple tasks at once
189
+ * const newTasks = await taskEntity.createMany([
190
+ * {
191
+ * title: 'Implement feature X',
192
+ * description: 'Add the new feature with tests',
193
+ * status: 'todo',
194
+ * assigneeId: 'user-456'
195
+ * },
196
+ * {
197
+ * title: 'Review pull requests',
198
+ * description: 'Review pending PRs',
199
+ * status: 'in_progress',
200
+ * assigneeId: 'user-789'
201
+ * }
202
+ * ]);
203
+ *
204
+ * console.log(`Created ${newTasks.length} tasks`);
205
+ * ```
206
+ */
207
+ createMany(data: EntityTypeOnlyMutable<EC>[]): Promise<EntityType<EC>[]>;
208
+ /**
209
+ * Updates an existing entity in the database
210
+ *
211
+ * Transforms the provided data to the database format with column name mapping
212
+ * and updates the specified entity in the database.
213
+ *
214
+ * @param {string} rowId - The ID of the entity to update
215
+ * @param {Partial<EntityTypeOnlyMutable<EC>>} data - The partial entity data to update
216
+ * @returns {Promise<EntityType<EC>>} The updated entity
217
+ * @example
218
+ * ```ts
219
+ * // Define a user entity configuration
220
+ * const userConfig = {
221
+ * tableBlockId: 'users-table',
222
+ * instanceType: {} as {
223
+ * name: string;
224
+ * email: string;
225
+ * role: string;
226
+ * lastLogin: string;
227
+ * }
228
+ * };
229
+ *
230
+ * // Create entity instance
231
+ * const userEntity = new Entity(userConfig);
232
+ *
233
+ * // Update a user's role
234
+ * const updatedUser = await userEntity.updateOne('8', {
235
+ * role: 'admin',
236
+ * lastLogin: new Date().toISOString()
237
+ * });
238
+ *
239
+ * console.log(`Updated user ${updatedUser.name}'s role to ${updatedUser.role}`);
240
+ * ```
241
+ */
242
+ updateOne(rowId: string, data: Partial<EntityTypeOnlyMutable<EC>>): Promise<EntityType<EC>>;
243
+ /**
244
+ * Deletes an entity from the database
245
+ *
246
+ * @param {string} id - The ID of the entity to delete
247
+ * @returns {Promise<void>}
248
+ * @example
249
+ * ```ts
250
+ * // Define a comment entity configuration
251
+ * const commentConfig = {
252
+ * tableBlockId: 'comments-table',
253
+ * instanceType: {} as {
254
+ * text: string;
255
+ * postId: string;
256
+ * authorId: string;
257
+ * }
258
+ * };
259
+ *
260
+ * // Create entity instance
261
+ * const commentEntity = new Entity(commentConfig);
262
+ *
263
+ * // Delete a comment
264
+ * await commentEntity.deleteOne('comment-456');
265
+ * console.log('Comment deleted successfully');
266
+ * ```
267
+ */
268
+ deleteOne(id: string): Promise<void>;
269
+ /**
270
+ * Deletes multiple entities from the database
271
+ *
272
+ * Processes deletions in chunks to handle large arrays efficiently,
273
+ * executing multiple deletion operations in parallel when needed.
274
+ *
275
+ * @param {string[]} ids - Array of entity IDs to delete
276
+ * @returns {Promise<void>}
277
+ * @example
278
+ * ```ts
279
+ * // Define a comment entity configuration
280
+ * const commentConfig = {
281
+ * tableBlockId: 'comments-table',
282
+ * instanceType: {} as {
283
+ * text: string;
284
+ * postId: string;
285
+ * authorId: string;
286
+ * }
287
+ * };
288
+ *
289
+ * // Create entity instance
290
+ * const commentEntity = new Entity(commentConfig);
291
+ *
292
+ * // Delete multiple comments at once
293
+ * await commentEntity.deleteMany(['comment-123', 'comment-456', 'comment-789']);
294
+ * console.log('Comments deleted successfully');
295
+ * ```
296
+ */
297
+ deleteMany(ids: string[]): Promise<void>;
298
+ }
299
+ //# sourceMappingURL=Entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE;IAClE,YAAY,EAAE,MAAM,CAAC;IACrB,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E,MAAM,EAAE;CAS/B"}
package/dist/Entity.js ADDED
@@ -0,0 +1,329 @@
1
+ import { DataApiService } from "@blockscom/blocks-client-api";
2
+ const DATA_OPERATIONS_CHUNK_SIZE = 500;
3
+ const arrayToChunks = (array, chunkSize) => {
4
+ const chunks = [];
5
+ for (let i = 0; i < array.length; i += chunkSize) {
6
+ chunks.push(array.slice(i, i + chunkSize));
7
+ }
8
+ return chunks;
9
+ };
10
+ /**
11
+ * Entity class for performing CRUD operations on data entities
12
+ *
13
+ * This class provides methods to create, read, update, and delete entity records,
14
+ * handling the mapping between frontend property names and database column names.
15
+ *
16
+ * @class Entity
17
+ * @template EC - Entity configuration type
18
+ */
19
+ export class Entity {
20
+ tableBlockId;
21
+ dataApiService;
22
+ /**
23
+ * Creates a new Entity instance
24
+ * @param {EC} config - Configuration for the entity
25
+ * @param {string} token - The token for the application
26
+ */
27
+ constructor(config, { token } = {}) {
28
+ this.tableBlockId = config.tableBlockId;
29
+ this.dataApiService = new DataApiService({ token });
30
+ }
31
+ /**
32
+ * Retrieves a single entity by filters
33
+ *
34
+ * Fetches an entity from the database and transforms it to the frontend format
35
+ * with properly mapped property names.
36
+ *
37
+ * @param {Record<string, any>} filters - Filters to identify the entity (e.g., { id: "123" } or { email: "user@example.com" })
38
+ * @returns {Promise<EntityType<EC> | null>} The entity if found, null otherwise
39
+ * @example
40
+ * ```ts
41
+ * // Define a user entity configuration
42
+ * const userConfig = {
43
+ * tableBlockId: 'users-table',
44
+ * instanceType: {} as {
45
+ * name: string;
46
+ * email: string;
47
+ * }
48
+ * };
49
+ *
50
+ * // Create entity instance
51
+ * const userEntity = new Entity(userConfig);
52
+ *
53
+ * // Find a user by email
54
+ * const user = await userEntity.findOne({ email: 'user@example.com' });
55
+ * if (user) {
56
+ * console.log(`Found user: ${user.name}, email: ${user.email}`);
57
+ * }
58
+ * ```
59
+ */
60
+ async findOne(filters) {
61
+ try {
62
+ const instance = (await this.dataApiService.getTableRow(this.tableBlockId, filters));
63
+ return instance;
64
+ }
65
+ catch (error) {
66
+ console.warn(error);
67
+ return null;
68
+ }
69
+ }
70
+ /**
71
+ * Retrieves multiple entities that match the provided filters
72
+ *
73
+ * Fetches entities from the database and transforms them to the frontend format
74
+ * with properly mapped property names.
75
+ *
76
+ * @param {any} [filters] - Optional filters to apply to the query
77
+ * @returns {Promise<Array<EntityType<EC>>>} Array of matching entities
78
+ * @example
79
+ * ```ts
80
+ * // Define a product entity configuration
81
+ * const productConfig = {
82
+ * tableBlockId: 'products-table',
83
+ * instanceType: {} as {
84
+ * name: string;
85
+ * price: number;
86
+ * category: string;
87
+ * }
88
+ * };
89
+ *
90
+ * // Create entity instance
91
+ * const productEntity = new Entity(productConfig);
92
+ *
93
+ * // Find all products in a specific category
94
+ * const products = await productEntity.findMany({ category: 'electronics' });
95
+ *
96
+ * // Process the results
97
+ * products.forEach(product => {
98
+ * console.log(`${product.name}: $${product.price}`);
99
+ * });
100
+ * ```
101
+ */
102
+ async findMany(filters) {
103
+ try {
104
+ const response = await this.dataApiService.getTableData(this.tableBlockId, filters);
105
+ // Ensure we're working with an array
106
+ const instances = Array.isArray(response) ? response : response ? [response] : [];
107
+ return instances;
108
+ }
109
+ catch (error) {
110
+ console.warn(error);
111
+ throw error;
112
+ }
113
+ }
114
+ /**
115
+ * Creates a new entity in the database
116
+ *
117
+ * Transforms the provided data to the database format with column name mapping
118
+ * and inserts it into the database.
119
+ *
120
+ * @param {EntityTypeOnlyMutable<EC>} data - The entity data to create
121
+ * @returns {Promise<EntityType<EC>>} The created entity with system fields
122
+ * @example
123
+ * ```ts
124
+ * // Define a task entity configuration
125
+ * const taskConfig = {
126
+ * tableBlockId: 'tasks-table',
127
+ * instanceType: {} as {
128
+ * title: string;
129
+ * description: string;
130
+ * status: 'todo' | 'in_progress' | 'done';
131
+ * assigneeId: string;
132
+ * }
133
+ * };
134
+ *
135
+ * // Create entity instance
136
+ * const taskEntity = new Entity(taskConfig);
137
+ *
138
+ * // Create a new task
139
+ * const newTask = await taskEntity.create({
140
+ * title: 'Implement feature X',
141
+ * description: 'Add the new feature with tests',
142
+ * status: 'todo',
143
+ * assigneeId: 'user-456'
144
+ * });
145
+ *
146
+ * console.log(`Created task with ID: ${newTask.id}`);
147
+ * ```
148
+ */
149
+ async create(data) {
150
+ try {
151
+ const [newInstance] = (await this.dataApiService.insertTableRow(this.tableBlockId, data));
152
+ return newInstance;
153
+ }
154
+ catch (error) {
155
+ console.warn(error);
156
+ throw error;
157
+ }
158
+ }
159
+ /**
160
+ * Creates multiple new entities in the database
161
+ *
162
+ * Transforms the provided array of data to the database format with column name mapping
163
+ * and inserts them into the database in a single operation.
164
+ *
165
+ * @param {EntityTypeOnlyMutable<EC>[]} data - Array of entity data to create
166
+ * @returns {Promise<EntityType<EC>[]>} Array of created entities with system fields
167
+ * @example
168
+ * ```ts
169
+ * // Define a task entity configuration
170
+ * const taskConfig = {
171
+ * tableBlockId: 'tasks-table',
172
+ * instanceType: {} as {
173
+ * title: string;
174
+ * description: string;
175
+ * status: 'todo' | 'in_progress' | 'done';
176
+ * assigneeId: string;
177
+ * }
178
+ * };
179
+ *
180
+ * // Create entity instance
181
+ * const taskEntity = new Entity(taskConfig);
182
+ *
183
+ * // Create multiple tasks at once
184
+ * const newTasks = await taskEntity.createMany([
185
+ * {
186
+ * title: 'Implement feature X',
187
+ * description: 'Add the new feature with tests',
188
+ * status: 'todo',
189
+ * assigneeId: 'user-456'
190
+ * },
191
+ * {
192
+ * title: 'Review pull requests',
193
+ * description: 'Review pending PRs',
194
+ * status: 'in_progress',
195
+ * assigneeId: 'user-789'
196
+ * }
197
+ * ]);
198
+ *
199
+ * console.log(`Created ${newTasks.length} tasks`);
200
+ * ```
201
+ */
202
+ async createMany(data) {
203
+ try {
204
+ const newInstances = (await this.dataApiService.insertTableRows(this.tableBlockId, data));
205
+ return newInstances;
206
+ }
207
+ catch (error) {
208
+ console.warn(error);
209
+ throw error;
210
+ }
211
+ }
212
+ /**
213
+ * Updates an existing entity in the database
214
+ *
215
+ * Transforms the provided data to the database format with column name mapping
216
+ * and updates the specified entity in the database.
217
+ *
218
+ * @param {string} rowId - The ID of the entity to update
219
+ * @param {Partial<EntityTypeOnlyMutable<EC>>} data - The partial entity data to update
220
+ * @returns {Promise<EntityType<EC>>} The updated entity
221
+ * @example
222
+ * ```ts
223
+ * // Define a user entity configuration
224
+ * const userConfig = {
225
+ * tableBlockId: 'users-table',
226
+ * instanceType: {} as {
227
+ * name: string;
228
+ * email: string;
229
+ * role: string;
230
+ * lastLogin: string;
231
+ * }
232
+ * };
233
+ *
234
+ * // Create entity instance
235
+ * const userEntity = new Entity(userConfig);
236
+ *
237
+ * // Update a user's role
238
+ * const updatedUser = await userEntity.updateOne('8', {
239
+ * role: 'admin',
240
+ * lastLogin: new Date().toISOString()
241
+ * });
242
+ *
243
+ * console.log(`Updated user ${updatedUser.name}'s role to ${updatedUser.role}`);
244
+ * ```
245
+ */
246
+ async updateOne(rowId, data) {
247
+ try {
248
+ const instance = (await this.dataApiService.updateTableRow(this.tableBlockId, rowId, data));
249
+ return instance;
250
+ }
251
+ catch (error) {
252
+ console.warn(error);
253
+ throw error;
254
+ }
255
+ }
256
+ /**
257
+ * Deletes an entity from the database
258
+ *
259
+ * @param {string} id - The ID of the entity to delete
260
+ * @returns {Promise<void>}
261
+ * @example
262
+ * ```ts
263
+ * // Define a comment entity configuration
264
+ * const commentConfig = {
265
+ * tableBlockId: 'comments-table',
266
+ * instanceType: {} as {
267
+ * text: string;
268
+ * postId: string;
269
+ * authorId: string;
270
+ * }
271
+ * };
272
+ *
273
+ * // Create entity instance
274
+ * const commentEntity = new Entity(commentConfig);
275
+ *
276
+ * // Delete a comment
277
+ * await commentEntity.deleteOne('comment-456');
278
+ * console.log('Comment deleted successfully');
279
+ * ```
280
+ */
281
+ async deleteOne(id) {
282
+ try {
283
+ await this.dataApiService.deleteTableRow(this.tableBlockId, id);
284
+ }
285
+ catch (error) {
286
+ console.warn(error);
287
+ throw error;
288
+ }
289
+ }
290
+ /**
291
+ * Deletes multiple entities from the database
292
+ *
293
+ * Processes deletions in chunks to handle large arrays efficiently,
294
+ * executing multiple deletion operations in parallel when needed.
295
+ *
296
+ * @param {string[]} ids - Array of entity IDs to delete
297
+ * @returns {Promise<void>}
298
+ * @example
299
+ * ```ts
300
+ * // Define a comment entity configuration
301
+ * const commentConfig = {
302
+ * tableBlockId: 'comments-table',
303
+ * instanceType: {} as {
304
+ * text: string;
305
+ * postId: string;
306
+ * authorId: string;
307
+ * }
308
+ * };
309
+ *
310
+ * // Create entity instance
311
+ * const commentEntity = new Entity(commentConfig);
312
+ *
313
+ * // Delete multiple comments at once
314
+ * await commentEntity.deleteMany(['comment-123', 'comment-456', 'comment-789']);
315
+ * console.log('Comments deleted successfully');
316
+ * ```
317
+ */
318
+ async deleteMany(ids) {
319
+ try {
320
+ const idsChunks = arrayToChunks(ids, DATA_OPERATIONS_CHUNK_SIZE);
321
+ await Promise.all(idsChunks.map((idsChunk) => this.dataApiService.deleteTableRows(this.tableBlockId, idsChunk)));
322
+ }
323
+ catch (error) {
324
+ console.warn(error);
325
+ throw error;
326
+ }
327
+ }
328
+ }
329
+ //# sourceMappingURL=Entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Entity.js","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC,MAAM,aAAa,GAAG,CAAI,KAAU,EAAE,SAAiB,EAAS,EAAE;IAChE,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;QACjD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAC7C,CA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QACd,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,KAAK,CAAC,SAAS,CAAC,EAAU;QACxB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAClE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,KAAK,CAAC,UAAU,CAAC,GAAa;QAC5B,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,EAAE,0BAA0B,CAAC,CAAC;YACjE,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
package/dist/Page.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Configuration for defining a page
3
+ *
4
+ * This interface is used to define the basic structure of a page configuration,
5
+ * including its unique identifier.
6
+ *
7
+ * @interface PageConfig
8
+ * @property {string} pageBlockId - Unique identifier for the page
9
+ * @property {string} pageName - Name of the page
10
+ */
11
+ export interface PageConfig {
12
+ pageBlockId: string;
13
+ pageName: string;
14
+ }
15
+ /**
16
+ * Page class for managing application pages and their URLs
17
+ *
18
+ * This class provides methods to work with application pages, including
19
+ * generating proper URLs and handling URL parameters.
20
+ *
21
+ * @class Page
22
+ * @template PC - Page configuration type
23
+ */
24
+ export declare class Page<PC extends PageConfig = PageConfig> {
25
+ private pageBlockId;
26
+ private pageName;
27
+ private appId;
28
+ /**
29
+ * Creates a new Page instance
30
+ * @param {PC} config - Configuration for the page
31
+ * @param {string} appId - The application identifier
32
+ */
33
+ constructor(config: PC, appId: string);
34
+ /**
35
+ * @deprecated
36
+ * This method is deprecated and will be removed in a future version.
37
+ * Use the new routing utilities for URL generation instead.
38
+ *
39
+ * Generates a URL for this page, including optional search parameters.
40
+ *
41
+ * @param {Record<string, string>} [searchParams={}] - Optional search parameters to append to the URL
42
+ * @returns {string} The generated URL for the page with the given search parameters
43
+ */
44
+ getUrl(searchParams?: Record<string, string>): string;
45
+ /**
46
+ * @deprecated
47
+ * This method is deprecated and will be removed in a future version.
48
+ * Use a dedicated query parameter parsing utility instead.
49
+ *
50
+ * Parses and returns the current URL's search parameters as an object.
51
+ *
52
+ * @returns {Record<string, string>} An object representation of the URL search parameters
53
+ */
54
+ getParams(): Record<string, string>;
55
+ }
56
+ //# sourceMappingURL=Page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Page.d.ts","sourceRoot":"","sources":["../src/Page.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,qBAAa,IAAI,CAAC,EAAE,SAAS,UAAU,GAAG,UAAU;IAClD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAAS;IAEtB;;;;OAIG;gBACS,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM;IAMrC;;;;;;;;;OASG;IACH,MAAM,CAAC,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;IAKhD;;;;;;;;OAQG;IACH,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAIpC"}