ampless 1.0.0-beta.52 → 1.0.0-beta.53

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +33 -14
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1829,17 +1829,31 @@ declare function escapeXml(s: string): string;
1829
1829
  *
1830
1830
  * Variable 'body' has an invalid value.
1831
1831
  *
1832
- * On the read side two wire shapes coexist:
1833
- *
1834
- * - JSON-encoded string — what the auto-generated CRUD resolver and
1835
- * custom resolvers usually return.
1836
- * - Native object / Map DynamoDBDocumentClient unmarshals
1837
- * AWSJSON-stored maps straight into JS objects when read directly
1838
- * from DynamoDB (the path used by the trusted processor and the
1839
- * MCP Lambda).
1840
- *
1841
- * `decodeAwsJson` handles both: pass strings through `JSON.parse`,
1842
- * everything else as-is.
1832
+ * On the read side there are two FUNDAMENTALLY DIFFERENT paths, and they
1833
+ * must be handled differently — the value's runtime shape is NOT enough
1834
+ * to disambiguate them:
1835
+ *
1836
+ * 1. GraphQL wire read (auto-generated CRUD resolver, custom resolvers,
1837
+ * raw GraphQL fetch) the value arrives as a JSON-encoded string,
1838
+ * regardless of the underlying type. Use `decodeAwsJson` to parse it
1839
+ * back into the native JS value.
1840
+ *
1841
+ * 2. Direct DynamoDBDocumentClient read (the trusted processor and the
1842
+ * MCP Lambda read straight from DynamoDB) — DocumentClient already
1843
+ * unmarshals AWSJSON-backed attributes into native JS types
1844
+ * (S→string, N→number, BOOL→boolean, M→object). The value is ALREADY
1845
+ * the correct JS type and must be used AS-IS. Do NOT run
1846
+ * `decodeAwsJson` / `JSON.parse` on it.
1847
+ *
1848
+ * Why the distinction is load-bearing: a native scalar STRING from path 2
1849
+ * is indistinguishable, by type alone, from a wire string on path 1. But
1850
+ * `decodeAwsJson("1470")` === `JSON.parse("1470")` === the number `1470`,
1851
+ * so running the decoder on a DocumentClient scalar string silently
1852
+ * double-decodes numeric-looking settings/bodies (this caused a
1853
+ * site-wide 500). The "non-strings pass through unchanged" tolerance of
1854
+ * `decodeAwsJson` does NOT make it safe on DocumentClient reads — scalar
1855
+ * strings are exactly the case it corrupts. Pick the decoder by read PATH,
1856
+ * never by the value's runtime shape.
1843
1857
  */
1844
1858
  /**
1845
1859
  * Serialise a value for an AWSJSON variable. `undefined` / `null` both
@@ -1848,9 +1862,14 @@ declare function escapeXml(s: string): string;
1848
1862
  */
1849
1863
  declare function encodeAwsJson(value: unknown): string;
1850
1864
  /**
1851
- * Deserialise an AWSJSON value from a GraphQL / DynamoDB read.
1852
- * Tolerates both the wire-string shape and the auto-unmarshalled
1853
- * native value. Throws if the string is not valid JSON.
1865
+ * Deserialise an AWSJSON value from a GraphQL wire read (path 1 above).
1866
+ * Non-string inputs pass through unchanged; strings go through
1867
+ * `JSON.parse` and throw if not valid JSON.
1868
+ *
1869
+ * Only call this on values read over the GraphQL wire. Do NOT call it on
1870
+ * values read directly via DynamoDBDocumentClient — those are already
1871
+ * native JS types, and a native scalar string (e.g. "1470") would be
1872
+ * double-decoded into a number. See the module doc block above.
1854
1873
  */
1855
1874
  declare function decodeAwsJson(value: unknown): unknown;
1856
1875
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ampless",
3
- "version": "1.0.0-beta.52",
3
+ "version": "1.0.0-beta.53",
4
4
  "description": "Serverless CMS for AWS Amplify",
5
5
  "license": "MIT",
6
6
  "type": "module",