resora 1.2.12 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1561,6 +1561,12 @@ var BaseSerializer = class {
1561
1561
  return extractResponseFromCtx(getCtx() ?? this.constructor.ctx);
1562
1562
  }
1563
1563
  /**
1564
+ * Resolve the active request context for data transformation hooks.
1565
+ */
1566
+ resolveSerializationContext() {
1567
+ return getCtx() ?? this.constructor.ctx;
1568
+ }
1569
+ /**
1564
1570
  * Dispatch a body to a raw response object when it exposes a send() transport method.
1565
1571
  *
1566
1572
  * @param raw
@@ -1781,7 +1787,7 @@ var GenericResource = class GenericResource extends BaseSerializer {
1781
1787
  /**
1782
1788
  * Get the original resource data
1783
1789
  */
1784
- data() {
1790
+ data(_ctx) {
1785
1791
  return this.resource;
1786
1792
  }
1787
1793
  /**
@@ -1853,8 +1859,9 @@ var GenericResource = class GenericResource extends BaseSerializer {
1853
1859
  json() {
1854
1860
  if (!this.called.json) {
1855
1861
  this.called.json = true;
1856
- let data = normalizeSerializableData(this.data());
1857
- if (Array.isArray(data) && this.collects) data = data.map((item) => new this.collects(item).data());
1862
+ const ctx = this.resolveSerializationContext();
1863
+ let data = normalizeSerializableData(this.data(ctx));
1864
+ if (Array.isArray(data) && this.collects) data = data.map((item) => new this.collects(item).data(ctx));
1858
1865
  if (!Array.isArray(data) && data && typeof data.data !== "undefined") data = data.data;
1859
1866
  data = sanitizeConditionalAttributes(data);
1860
1867
  const paginationExtras = buildPaginationExtras(this.resource);
@@ -2098,15 +2105,15 @@ var ResourceCollection = class ResourceCollection extends BaseSerializer {
2098
2105
  getSourceData() {
2099
2106
  return Array.isArray(this.resource) ? this.resource : isArkormLikeCollection(this.resource) ? this.resource.all() : this.resource.data;
2100
2107
  }
2101
- resolveObjectData() {
2108
+ resolveObjectData(ctx) {
2102
2109
  let data = this.getSourceData();
2103
- if (this.collects) data = data.map((item) => new this.collects(item).data());
2110
+ if (this.collects) data = data.map((item) => new this.collects(item).data(ctx));
2104
2111
  return normalizeSerializableData(data);
2105
2112
  }
2106
2113
  /**
2107
2114
  * Get the original resource data
2108
2115
  */
2109
- data() {
2116
+ data(_ctx) {
2110
2117
  return this.getSourceData();
2111
2118
  }
2112
2119
  /**
@@ -2186,8 +2193,9 @@ var ResourceCollection = class ResourceCollection extends BaseSerializer {
2186
2193
  json() {
2187
2194
  if (!this.called.json) {
2188
2195
  this.called.json = true;
2189
- let data = this.data();
2190
- if (this.collects && this.data === ResourceCollection.prototype.data) data = data.map((item) => new this.collects(item).data());
2196
+ const ctx = this.resolveSerializationContext();
2197
+ let data = this.data(ctx);
2198
+ if (this.collects && this.data === ResourceCollection.prototype.data) data = data.map((item) => new this.collects(item).data(ctx));
2191
2199
  data = normalizeSerializableData(data);
2192
2200
  data = sanitizeConditionalAttributes(data);
2193
2201
  const paginationExtras = !Array.isArray(this.resource) ? buildPaginationExtras(this.resource) : {};
@@ -2228,7 +2236,7 @@ var ResourceCollection = class ResourceCollection extends BaseSerializer {
2228
2236
  */
2229
2237
  toObject() {
2230
2238
  this.called.toObject = true;
2231
- return this.resolveObjectData();
2239
+ return this.resolveObjectData(this.resolveSerializationContext());
2232
2240
  }
2233
2241
  /**
2234
2242
  * Convert resource to object format and return original data.
@@ -2447,7 +2455,7 @@ var Resource = class Resource extends BaseSerializer {
2447
2455
  /**
2448
2456
  * Get the original resource data
2449
2457
  */
2450
- data() {
2458
+ data(_ctx) {
2451
2459
  return this.toObject();
2452
2460
  }
2453
2461
  /**
@@ -2496,7 +2504,8 @@ var Resource = class Resource extends BaseSerializer {
2496
2504
  json() {
2497
2505
  if (!this.called.json) {
2498
2506
  this.called.json = true;
2499
- let data = normalizeSerializableData(this.data());
2507
+ const ctx = this.resolveSerializationContext();
2508
+ let data = normalizeSerializableData(this.data(ctx));
2500
2509
  if (!Array.isArray(data) && data && typeof data.data !== "undefined") data = data.data;
2501
2510
  data = sanitizeConditionalAttributes(data);
2502
2511
  const caseStyle = this.resolveSerializerCaseStyle(this.constructor);
package/dist/index.d.cts CHANGED
@@ -601,6 +601,10 @@ declare abstract class BaseSerializer<TResource = any> {
601
601
  * @returns
602
602
  */
603
603
  protected resolveRawResponse<TRawResponse>(response?: TRawResponse): TRawResponse | undefined;
604
+ /**
605
+ * Resolve the active request context for data transformation hooks.
606
+ */
607
+ protected resolveSerializationContext(): unknown;
604
608
  /**
605
609
  * Dispatch a body to a raw response object when it exposes a send() transport method.
606
610
  *
@@ -742,7 +746,7 @@ declare class ResourceCollection<R extends ResourceData[] | Collectible | Collec
742
746
  /**
743
747
  * Get the original resource data
744
748
  */
745
- data(): (R extends Collectible ? R["data"][number] : R extends PaginatorLike<infer TPaginatorData> ? TPaginatorData : R extends CollectionLike<infer TCollectionData> ? TCollectionData : R extends ResourceData[] ? R[number] : never)[];
749
+ data(_ctx?: unknown): (R extends Collectible ? R["data"][number] : R extends PaginatorLike<infer TPaginatorData> ? TPaginatorData : R extends CollectionLike<infer TCollectionData> ? TCollectionData : R extends ResourceData[] ? R[number] : never)[];
746
750
  /**
747
751
  * Get the current serialized output body.
748
752
  */
@@ -879,7 +883,7 @@ declare class Resource<R extends ResourceData | NonCollectible = ResourceData> e
879
883
  /**
880
884
  * Get the original resource data
881
885
  */
882
- data(): R extends NonCollectible ? R["data"] : R;
886
+ data(_ctx?: unknown): R extends NonCollectible ? R["data"] : R;
883
887
  /**
884
888
  * Get the current serialized output body.
885
889
  */
@@ -988,7 +992,7 @@ declare class GenericResource<R extends NonCollectible | Collectible | Collectio
988
992
  /**
989
993
  * Get the original resource data
990
994
  */
991
- data(): R;
995
+ data(_ctx?: unknown): R;
992
996
  /**
993
997
  * Get the current serialized output body.
994
998
  */
package/dist/index.d.mts CHANGED
@@ -601,6 +601,10 @@ declare abstract class BaseSerializer<TResource = any> {
601
601
  * @returns
602
602
  */
603
603
  protected resolveRawResponse<TRawResponse>(response?: TRawResponse): TRawResponse | undefined;
604
+ /**
605
+ * Resolve the active request context for data transformation hooks.
606
+ */
607
+ protected resolveSerializationContext(): unknown;
604
608
  /**
605
609
  * Dispatch a body to a raw response object when it exposes a send() transport method.
606
610
  *
@@ -742,7 +746,7 @@ declare class ResourceCollection<R extends ResourceData[] | Collectible | Collec
742
746
  /**
743
747
  * Get the original resource data
744
748
  */
745
- data(): (R extends Collectible ? R["data"][number] : R extends PaginatorLike<infer TPaginatorData> ? TPaginatorData : R extends CollectionLike<infer TCollectionData> ? TCollectionData : R extends ResourceData[] ? R[number] : never)[];
749
+ data(_ctx?: unknown): (R extends Collectible ? R["data"][number] : R extends PaginatorLike<infer TPaginatorData> ? TPaginatorData : R extends CollectionLike<infer TCollectionData> ? TCollectionData : R extends ResourceData[] ? R[number] : never)[];
746
750
  /**
747
751
  * Get the current serialized output body.
748
752
  */
@@ -879,7 +883,7 @@ declare class Resource<R extends ResourceData | NonCollectible = ResourceData> e
879
883
  /**
880
884
  * Get the original resource data
881
885
  */
882
- data(): R extends NonCollectible ? R["data"] : R;
886
+ data(_ctx?: unknown): R extends NonCollectible ? R["data"] : R;
883
887
  /**
884
888
  * Get the current serialized output body.
885
889
  */
@@ -988,7 +992,7 @@ declare class GenericResource<R extends NonCollectible | Collectible | Collectio
988
992
  /**
989
993
  * Get the original resource data
990
994
  */
991
- data(): R;
995
+ data(_ctx?: unknown): R;
992
996
  /**
993
997
  * Get the current serialized output body.
994
998
  */
package/dist/index.mjs CHANGED
@@ -1532,6 +1532,12 @@ var BaseSerializer = class {
1532
1532
  return extractResponseFromCtx(getCtx() ?? this.constructor.ctx);
1533
1533
  }
1534
1534
  /**
1535
+ * Resolve the active request context for data transformation hooks.
1536
+ */
1537
+ resolveSerializationContext() {
1538
+ return getCtx() ?? this.constructor.ctx;
1539
+ }
1540
+ /**
1535
1541
  * Dispatch a body to a raw response object when it exposes a send() transport method.
1536
1542
  *
1537
1543
  * @param raw
@@ -1752,7 +1758,7 @@ var GenericResource = class GenericResource extends BaseSerializer {
1752
1758
  /**
1753
1759
  * Get the original resource data
1754
1760
  */
1755
- data() {
1761
+ data(_ctx) {
1756
1762
  return this.resource;
1757
1763
  }
1758
1764
  /**
@@ -1824,8 +1830,9 @@ var GenericResource = class GenericResource extends BaseSerializer {
1824
1830
  json() {
1825
1831
  if (!this.called.json) {
1826
1832
  this.called.json = true;
1827
- let data = normalizeSerializableData(this.data());
1828
- if (Array.isArray(data) && this.collects) data = data.map((item) => new this.collects(item).data());
1833
+ const ctx = this.resolveSerializationContext();
1834
+ let data = normalizeSerializableData(this.data(ctx));
1835
+ if (Array.isArray(data) && this.collects) data = data.map((item) => new this.collects(item).data(ctx));
1829
1836
  if (!Array.isArray(data) && data && typeof data.data !== "undefined") data = data.data;
1830
1837
  data = sanitizeConditionalAttributes(data);
1831
1838
  const paginationExtras = buildPaginationExtras(this.resource);
@@ -2069,15 +2076,15 @@ var ResourceCollection = class ResourceCollection extends BaseSerializer {
2069
2076
  getSourceData() {
2070
2077
  return Array.isArray(this.resource) ? this.resource : isArkormLikeCollection(this.resource) ? this.resource.all() : this.resource.data;
2071
2078
  }
2072
- resolveObjectData() {
2079
+ resolveObjectData(ctx) {
2073
2080
  let data = this.getSourceData();
2074
- if (this.collects) data = data.map((item) => new this.collects(item).data());
2081
+ if (this.collects) data = data.map((item) => new this.collects(item).data(ctx));
2075
2082
  return normalizeSerializableData(data);
2076
2083
  }
2077
2084
  /**
2078
2085
  * Get the original resource data
2079
2086
  */
2080
- data() {
2087
+ data(_ctx) {
2081
2088
  return this.getSourceData();
2082
2089
  }
2083
2090
  /**
@@ -2157,8 +2164,9 @@ var ResourceCollection = class ResourceCollection extends BaseSerializer {
2157
2164
  json() {
2158
2165
  if (!this.called.json) {
2159
2166
  this.called.json = true;
2160
- let data = this.data();
2161
- if (this.collects && this.data === ResourceCollection.prototype.data) data = data.map((item) => new this.collects(item).data());
2167
+ const ctx = this.resolveSerializationContext();
2168
+ let data = this.data(ctx);
2169
+ if (this.collects && this.data === ResourceCollection.prototype.data) data = data.map((item) => new this.collects(item).data(ctx));
2162
2170
  data = normalizeSerializableData(data);
2163
2171
  data = sanitizeConditionalAttributes(data);
2164
2172
  const paginationExtras = !Array.isArray(this.resource) ? buildPaginationExtras(this.resource) : {};
@@ -2199,7 +2207,7 @@ var ResourceCollection = class ResourceCollection extends BaseSerializer {
2199
2207
  */
2200
2208
  toObject() {
2201
2209
  this.called.toObject = true;
2202
- return this.resolveObjectData();
2210
+ return this.resolveObjectData(this.resolveSerializationContext());
2203
2211
  }
2204
2212
  /**
2205
2213
  * Convert resource to object format and return original data.
@@ -2418,7 +2426,7 @@ var Resource = class Resource extends BaseSerializer {
2418
2426
  /**
2419
2427
  * Get the original resource data
2420
2428
  */
2421
- data() {
2429
+ data(_ctx) {
2422
2430
  return this.toObject();
2423
2431
  }
2424
2432
  /**
@@ -2467,7 +2475,8 @@ var Resource = class Resource extends BaseSerializer {
2467
2475
  json() {
2468
2476
  if (!this.called.json) {
2469
2477
  this.called.json = true;
2470
- let data = normalizeSerializableData(this.data());
2478
+ const ctx = this.resolveSerializationContext();
2479
+ let data = normalizeSerializableData(this.data(ctx));
2471
2480
  if (!Array.isArray(data) && data && typeof data.data !== "undefined") data = data.data;
2472
2481
  data = sanitizeConditionalAttributes(data);
2473
2482
  const caseStyle = this.resolveSerializerCaseStyle(this.constructor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resora",
3
- "version": "1.2.12",
3
+ "version": "1.3.0",
4
4
  "description": "A structured API response layer for Node.js and TypeScript with automatic JSON responses, collection support, and pagination handling.",
5
5
  "keywords": [
6
6
  "api",