Skip to content

Commit b326bb1

Browse files
releases/v2.7.0
- [c991495][michaeljymsgutierrez]: Updated release version from v2.6.3 to v2.7.0 - 2026-03-22 12:02:39 - [a2b7ba1][Chael Gutierrez]: Features/request alias getter (#232) - 2026-03-22 03:09:54
1 parent 5259891 commit b326bb1

15 files changed

Lines changed: 482 additions & 176 deletions

File tree

DOCS.md

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ single record object.</p>
5555
if <code>aliasRecords</code> is falsy). If it&#39;s a plain object, it&#39;s used directly
5656
(or an empty object if <code>aliasRecords</code> is falsy).</p>
5757
</dd>
58+
<dt><a href="#_addRequestAlias">_addRequestAlias(aliasName, requestHashKey)</a> ℗</dt>
59+
<dd><p>Adds a request alias to the request aliases object.</p>
60+
<p>This method maps a specific <code>aliasName</code> to a <code>requestHashKey</code> in the
61+
<code>requestAliases</code> dictionary. This allows the system to reference a
62+
specific request context using a human-readable alias.</p>
63+
</dd>
5864
<dt><a href="#_generateHashId">_generateHashId([object])</a> ⇒ <code>string</code> ℗</dt>
5965
<dd><p>Generates a hash ID based on the provided object.</p>
6066
<p>This method generates a unique hash ID by stringifying the given
@@ -332,6 +338,12 @@ not exist, it returns the provided <code>fallbackRecords</code> (if any).</p>
332338
<p>If <code>fallbackRecords</code> is a plain object, the method injects collection
333339
actions into it using <code>_injectCollectionActions</code> before returning it.</p>
334340
</dd>
341+
<dt><a href="#getRequestAlias">getRequestAlias(aliasName)</a> ⇒ <code>Object</code> | <code>null</code></dt>
342+
<dd><p>Retrieves the request data by resolving a readable alias to its latest request hash.</p>
343+
<p>The <code>requestAliases</code> property acts as a reference map, linking a human-readable
344+
alias to the hash of the most recent request. This method performs a lookup
345+
on that hash to return the actual request data.</p>
346+
</dd>
335347
<dt><a href="#createRecord">createRecord(collectionName, [collectionRecord], [collectionRecordRandomId])</a> ⇒ <code>Object</code></dt>
336348
<dd><p>Creates a new record in a specified collection.</p>
337349
<p>This method creates a new record in the collection with the given
@@ -376,8 +388,13 @@ request caching, and asynchronous loading of related resources.</p>
376388
<dt><a href="#_processRequestURL">_processRequestURL(requestOptions, resourceName, resourceId)</a></dt>
377389
<dd><p>Processes the URL for a request, constructing it from the resource name and ID.</p>
378390
</dd>
379-
<dt><a href="#_processRequestAlias">_processRequestAlias(resourceConfig, collectionRecords)</a></dt>
380-
<dd><p>Processes an alias for a request, adding it to the aliases store.</p>
391+
<dt><a href="#_processRequestAlias">_processRequestAlias(requestObject, collectionRecords)</a> ℗</dt>
392+
<dd><p>Processes an alias for a request, mapping both the records and the request hash.</p>
393+
<p>This method extracts the alias name from the request configuration and:</p>
394+
<ol>
395+
<li>Maps the alias name to the provided collection records in the aliases store.</li>
396+
<li>Maps the alias name to the generated request hash key in the request aliases store.</li>
397+
</ol>
381398
</dd>
382399
<dt><a href="#_processRequestOverride">_processRequestOverride(resourceConfig, requestOptions)</a></dt>
383400
<dd><p>Processes request overrides based on the provided configuration.</p>
@@ -646,6 +663,23 @@ if `aliasRecords` is falsy). If it's a plain object, it's used directly
646663
| aliasName | <code>string</code> | The name of the alias. |
647664
| aliasRecords | <code>Array</code> \| <code>Object</code> | The records to be aliased. |
648665

666+
<a name="_addRequestAlias"></a>
667+
668+
## \_addRequestAlias(aliasName, requestHashKey) ℗
669+
Adds a request alias to the request aliases object.
670+
671+
This method maps a specific `aliasName` to a `requestHashKey` in the
672+
`requestAliases` dictionary. This allows the system to reference a
673+
specific request context using a human-readable alias.
674+
675+
**Kind**: global function
676+
**Access**: private
677+
678+
| Param | Type | Description |
679+
| --- | --- | --- |
680+
| aliasName | <code>string</code> | The name of the alias for the request. |
681+
| requestHashKey | <code>string</code> | The unique hash key identifying the request. |
682+
649683
<a name="_generateHashId"></a>
650684

651685
## \_generateHashId([object]) ⇒ <code>string</code> ℗
@@ -1252,6 +1286,22 @@ actions into it using `_injectCollectionActions` before returning it.
12521286
| aliasName | <code>string</code> | The name of the alias to retrieve. |
12531287
| [fallbackRecords] | <code>Array</code> \| <code>Object</code> | Optional fallback records to return if the alias is not found. |
12541288

1289+
<a name="getRequestAlias"></a>
1290+
1291+
## getRequestAlias(aliasName) ⇒ <code>Object</code> \| <code>null</code>
1292+
Retrieves the request data by resolving a readable alias to its latest request hash.
1293+
1294+
The `requestAliases` property acts as a reference map, linking a human-readable
1295+
alias to the hash of the most recent request. This method performs a lookup
1296+
on that hash to return the actual request data.
1297+
1298+
**Kind**: global function
1299+
**Returns**: <code>Object</code> \| <code>null</code> - The request data object if found; otherwise, null.
1300+
1301+
| Param | Type | Description |
1302+
| --- | --- | --- |
1303+
| aliasName | <code>string</code> | The readable alias name to resolve. |
1304+
12551305
<a name="createRecord"></a>
12561306

12571307
## createRecord(collectionName, [collectionRecord], [collectionRecordRandomId]) ⇒ <code>Object</code>
@@ -1376,15 +1426,20 @@ Processes the URL for a request, constructing it from the resource name and ID.
13761426

13771427
<a name="_processRequestAlias"></a>
13781428

1379-
## \_processRequestAlias(resourceConfig, collectionRecords)
1380-
Processes an alias for a request, adding it to the aliases store.
1429+
## \_processRequestAlias(requestObject, collectionRecords) ℗
1430+
Processes an alias for a request, mapping both the records and the request hash.
1431+
1432+
This method extracts the alias name from the request configuration and:
1433+
1. Maps the alias name to the provided collection records in the aliases store.
1434+
2. Maps the alias name to the generated request hash key in the request aliases store.
13811435

13821436
**Kind**: global function
1437+
**Access**: private
13831438

13841439
| Param | Type | Description |
13851440
| --- | --- | --- |
1386-
| resourceConfig | <code>Object</code> | The configuration object for the resource request, containing the alias information. |
1387-
| collectionRecords | <code>Array</code> \| <code>Object</code> | The records to be aliased. Can be an array or an object. |
1441+
| requestObject | <code>Object</code> | The full request object used to generate the hash ID and containing the resource configuration. |
1442+
| collectionRecords | <code>Array</code> \| <code>Object</code> | The records to be aliased. Can be an array or a single object. |
13881443

13891444
<a name="_processRequestOverride"></a>
13901445

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<img src="https://github.com/michaeljymsgutierrez/arm-js-library/actions/workflows/ci-cd.yml/badge.svg" alt="cicd-badge-logo" />
1010
</a>
1111
<a href="https://www.npmjs.com/package/arm-js-library">
12-
<img src="https://img.shields.io/badge/npm_version-2.6.3-blue" alt="npm-badge-logo" />
12+
<img src="https://img.shields.io/badge/npm_version-2.7.0-blue" alt="npm-badge-logo" />
1313
</a>
1414
<a href="https://github.com/michaeljymsgutierrez/arm-js-library?tab=MIT-1-ov-file">
1515
<img src="https://img.shields.io/badge/license-MIT-green" alt="license-badge-logo" />
@@ -81,7 +81,7 @@ By centralizing data management and offering flexible access to it, ARM empowers
8181

8282
```javascript
8383
// Example usage in ReactJS/NextJS
84-
import { observer } from 'mobx-react-lite'
84+
import { observer } from 'mobx-react'
8585
import { ARM } from '@/components/providers/arm-config-provider'
8686

8787
const App = observer(() => {
@@ -506,6 +506,22 @@ See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/m
506506
</ul>
507507
```
508508
509+
- **getRequestAlias(aliasName)**
510+
- Retrieving the [returned object](#returned-object-request-functions-from-server) from the request functions.
511+
- See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/main/apps/create-next-app/src/app/demo/retrieve-functions-from-collections/get-request-alias)
512+
513+
```javascript
514+
const addresses = ARM.getRequestAlias('customerAddresses')
515+
516+
ARM.findAll('addresses', { alias: 'customerAddresses' })
517+
518+
<ul>
519+
{addresses.data.map((address, index) => (
520+
<li key={index}>{address.get('id')}</li>
521+
))}
522+
</ul>
523+
```
524+
509525
#### Create collection record function
510526
511527
---
@@ -588,7 +604,7 @@ See example [here](https://github.com/michaeljymsgutierrez/arm-js-library/tree/m
588604
"type": "addresses",
589605
"attributes": {
590606
"address1": "Test Address 1",
591-
"address2": "171872.6.3222",
607+
"address2": "171872.7.0222",
592608
"kind": "office",
593609
"label": "Anabu Hills",
594610
"latitude": "14.394261",
@@ -1063,4 +1079,4 @@ const addresses = [
10631079
10641080
## License
10651081
1066-
This project is licensed under the MIT License.
1082+
This project is licensed under the [MIT](https://github.com/michaeljymsgutierrez/arm-js-library/blob/main/LICENSE.md) License.

apps/create-next-app/next.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
turbopack: {
4+
root: '../../',
5+
},
36
async redirects() {
47
return [
58
{

apps/create-next-app/src/app/demo/page.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const DemoPage = () => {
4040
'/demo/request-functions-from-server/query',
4141
'/demo/request-functions-from-server/returned-object',
4242
'/demo/retrieve-functions-from-collections/get-alias',
43+
'/demo/retrieve-functions-from-collections/get-request-alias',
4344
'/demo/retrieve-functions-from-collections/get-collection',
4445
'/demo/retrieve-functions-from-collections/peek-all',
4546
'/demo/retrieve-functions-from-collections/peek-record',
@@ -54,10 +55,18 @@ const DemoPage = () => {
5455
return (
5556
<div className="flex justify-center items-center min-h-screen bg-gray-100 p-5">
5657
<div className="bg-white p-8 rounded-lg shadow-xl w-full max-w-2xl">
57-
<h1 className="text-3xl font-bold text-center mb-8">Demo Links</h1>
58+
<a href="https://www.npmjs.com/package/arm-js-library">
59+
<img
60+
src="https://assets-omega-neon.vercel.app/images/arm-js-title-logo.png"
61+
alt="arm-js-logo"
62+
height="200"
63+
width="143.7"
64+
className="my-8 mx-auto"
65+
/>
66+
</a>
5867
<input
5968
type="text"
60-
placeholder="Search demos..."
69+
placeholder="Search demo links..."
6170
className="w-full p-3 mb-6 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
6271
value={searchTerm}
6372
onChange={(e) => setSearchTerm(e.target.value)}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use client'
2+
3+
import { ARM } from '@/components/providers/arm-config-provider'
4+
5+
const Controller = () => {
6+
return {
7+
addresses: ARM.getRequestAlias('customerAddresses'),
8+
}
9+
}
10+
11+
export default Controller
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use client'
2+
3+
import { ARM } from '@/components/providers/arm-config-provider'
4+
5+
const Model = () => {
6+
return {
7+
addresses: ARM.findAll('addresses', { alias: 'customerAddresses' }),
8+
}
9+
}
10+
11+
export default Model
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use client'
2+
3+
import { observer } from 'mobx-react'
4+
import Controller from './controller'
5+
import Model from './model'
6+
7+
const Page = observer(() => {
8+
const controller = Controller()
9+
const { isLoading } = Model()
10+
11+
return (
12+
<table>
13+
<thead>
14+
<tr>
15+
<th>ADDRESS1</th>
16+
<th>ADDRESS2</th>
17+
<th>CITY</th>
18+
<th>POST CODE</th>
19+
<th>LANDMARK</th>
20+
<th>KIND</th>
21+
<th>LABEL</th>
22+
<th>LONGITUDE</th>
23+
<th>LATITUDE</th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
{isLoading && (
28+
<tr>
29+
<td colSpan="9">Loading...</td>
30+
</tr>
31+
)}
32+
33+
{!isLoading &&
34+
controller.addresses?.data.map((address) => (
35+
<tr key={address.get('id')}>
36+
<td>{address.get('attributes.address1')}</td>
37+
<td>{address.get('attributes.address2')}</td>
38+
<td>{address.get('attributes.city')}</td>
39+
<td>{address.get('attributes.post-code')}</td>
40+
<td>{address.get('attributes.landmark')}</td>
41+
<td>{address.get('attributes.kind')}</td>
42+
<td>{address.get('attributes.label')}</td>
43+
<td>{address.get('attributes.longitude')}</td>
44+
<td>{address.get('attributes.latitude')}</td>
45+
</tr>
46+
))}
47+
</tbody>
48+
</table>
49+
)
50+
})
51+
52+
export default Page

0 commit comments

Comments
 (0)