@amplifyup/sdk 0.1.63 → 0.1.64

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/server.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { i as AmplifyUpTarget, P as PageConfig, A as AmplifyContentMeta } from './types-Db_eLrfU.mjs';
2
- export { r as resolveAmplifyUpTarget, j as resolveAmplifyUpUrls } from './types-Db_eLrfU.mjs';
1
+ import { i as AmplifyUpTarget, P as PageConfig, A as AmplifyContentMeta } from './types-C32MgOiv.mjs';
2
+ export { r as resolveAmplifyUpTarget, j as resolveAmplifyUpUrls } from './types-C32MgOiv.mjs';
3
3
  export { A as AMPLIFYUP_EDITOR_ROUTE, i as isAmplifyUpEditorRoute } from './reservedRoutes-aGgViBDM.mjs';
4
- export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-DIZjc7st.mjs';
4
+ export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-DuRilU_n.mjs';
5
5
 
6
6
  /**
7
7
  * Compact variant-key codec for URLs and Edge `variants` query params.
package/dist/server.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { i as AmplifyUpTarget, P as PageConfig, A as AmplifyContentMeta } from './types-Db_eLrfU.js';
2
- export { r as resolveAmplifyUpTarget, j as resolveAmplifyUpUrls } from './types-Db_eLrfU.js';
1
+ import { i as AmplifyUpTarget, P as PageConfig, A as AmplifyContentMeta } from './types-C32MgOiv.js';
2
+ export { r as resolveAmplifyUpTarget, j as resolveAmplifyUpUrls } from './types-C32MgOiv.js';
3
3
  export { A as AMPLIFYUP_EDITOR_ROUTE, i as isAmplifyUpEditorRoute } from './reservedRoutes-aGgViBDM.js';
4
- export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-3AXnQgzO.js';
4
+ export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-BLjZYjHJ.js';
5
5
 
6
6
  /**
7
7
  * Compact variant-key codec for URLs and Edge `variants` query params.
package/dist/server.js CHANGED
@@ -100,6 +100,16 @@ function isComposerPreview() {
100
100
 
101
101
  // src/field-envelope.ts
102
102
  var FIELDS_BRAND = Symbol("amplifyup.fields");
103
+ var IDENTIFIER_KEYS = /* @__PURE__ */ new Set([
104
+ "id",
105
+ "_id",
106
+ "slug",
107
+ "key",
108
+ "_key",
109
+ "docId",
110
+ "_type",
111
+ "type"
112
+ ]);
103
113
  function isBrandedFields(value) {
104
114
  return !!value && typeof value === "object" && FIELDS_BRAND in value;
105
115
  }
@@ -121,21 +131,70 @@ function isPortableImageShape(value) {
121
131
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
122
132
  return "url" in value;
123
133
  }
124
- function isEntryRefItem(value) {
125
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
126
- const rec = value;
127
- return typeof rec.id === "string" && rec.id.trim().length > 0 || typeof rec._id === "string" && rec._id.trim().length > 0 || typeof rec.docId === "string" && rec.docId.trim().length > 0;
134
+ function isIdentifierKey(key) {
135
+ return IDENTIFIER_KEYS.has(key);
128
136
  }
129
- function isRepeaterArray(value) {
137
+ function isRecordList(value) {
130
138
  if (!Array.isArray(value) || value.length === 0) return false;
131
139
  const sample = value.find((item) => item != null);
132
140
  if (sample === void 0) return false;
133
141
  if (typeof sample !== "object" || Array.isArray(sample)) return false;
134
142
  if (isPortableImageShape(sample)) return false;
135
- if (isEntryRefItem(sample)) return false;
136
143
  if (sample.$$typeof) return false;
137
144
  return true;
138
145
  }
146
+ function isFieldRef(value) {
147
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
148
+ const rec = value;
149
+ return typeof rec.providerId === "string" && !!rec.providerId && typeof rec.entity === "string" && !!rec.entity && typeof rec.id === "string" && !!rec.id;
150
+ }
151
+ function isListOwner(value) {
152
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
153
+ const rec = value;
154
+ return typeof rec.providerId === "string" && !!rec.providerId && typeof rec.entity === "string" && !!rec.entity;
155
+ }
156
+ function listOwnerFromConnection(conn) {
157
+ if (!conn || typeof conn !== "object") return void 0;
158
+ if (conn.mode === "query") {
159
+ const providerId = String(conn.spec?.providerId || "").trim();
160
+ const entity = String(conn.spec?.entity || "").trim();
161
+ return providerId && entity ? { providerId, entity } : void 0;
162
+ }
163
+ if (conn.mode === "item" || conn.mode === "items") {
164
+ const providerId = String(conn.providerId || "").trim();
165
+ const entity = String(conn.entity || "").trim();
166
+ return providerId && entity ? { providerId, entity } : void 0;
167
+ }
168
+ return void 0;
169
+ }
170
+ function listOwnerFromSpec(spec) {
171
+ const providerId = String(spec?.providerId || "").trim();
172
+ const entity = String(spec?.entity || "").trim();
173
+ return providerId && entity ? { providerId, entity } : void 0;
174
+ }
175
+ function isEnvelopeSources(value) {
176
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
177
+ const rec = value;
178
+ return rec.connections != null || rec.reads != null;
179
+ }
180
+ function normalizeEnvelopeSources(sources) {
181
+ if (!sources) return {};
182
+ if (isEnvelopeSources(sources) && !("mode" in sources)) {
183
+ return sources;
184
+ }
185
+ return { connections: sources };
186
+ }
187
+ function listOwnerForField(fieldName, props, sources) {
188
+ const { connections, reads } = normalizeEnvelopeSources(sources);
189
+ const resourceName = reads?.[fieldName]?.resource || fieldName;
190
+ const fromConn = listOwnerFromConnection(connections?.[resourceName]);
191
+ if (fromConn) return fromConn;
192
+ const paging = props?.[`${fieldName}Pagination`];
193
+ if (paging && typeof paging === "object" && !Array.isArray(paging)) {
194
+ return listOwnerFromSpec(paging.spec);
195
+ }
196
+ return void 0;
197
+ }
139
198
  function joinPath(prefix, key) {
140
199
  return prefix ? `${prefix}.${key}` : key;
141
200
  }
@@ -143,61 +202,101 @@ function emptyValue(raw) {
143
202
  if (raw === void 0) return null;
144
203
  return raw;
145
204
  }
146
- function toFieldEnvelopes(source, prefix = "") {
205
+ function rowId(raw) {
206
+ const candidates = [raw.id, raw._id, raw.docId, raw.key, raw._key];
207
+ for (const c of candidates) {
208
+ if (typeof c === "string" && c.trim()) return c;
209
+ }
210
+ return "";
211
+ }
212
+ function withLeaf(envelope, scope) {
213
+ if (isFieldRef(scope?.ref)) envelope.ref = scope.ref;
214
+ else if (scope?.readOnly) envelope.readOnly = true;
215
+ return envelope;
216
+ }
217
+ function toFieldEnvelopes(source, prefix = "", scope) {
218
+ const ctx = isFieldRef(scope) ? { ref: scope } : scope || {};
147
219
  const input = source && typeof source === "object" && !Array.isArray(source) ? source : {};
148
220
  if (isBrandedFields(input)) {
149
221
  return input;
150
222
  }
151
223
  const out = {};
152
224
  for (const [key, raw] of Object.entries(input)) {
225
+ if (isIdentifierKey(key) && (typeof raw === "string" || raw == null)) {
226
+ out[key] = raw ?? "";
227
+ continue;
228
+ }
153
229
  const path = joinPath(prefix, key);
154
230
  if (isFieldEnvelope(raw)) {
155
231
  const inner = raw.value;
156
- if (isRepeaterArray(inner)) {
232
+ if (isRecordList(inner)) {
233
+ const owner = ctx.owners?.(key);
157
234
  out[key] = {
158
- value: envelopeRepeaterItems(inner, raw.name || path),
235
+ value: envelopeListRows(inner, owner),
159
236
  name: raw.name || path
160
237
  };
161
238
  continue;
162
239
  }
163
- out[key] = { value: raw.value ?? null, name: raw.name || path };
240
+ out[key] = withLeaf(
241
+ { value: raw.value ?? null, name: raw.name || path },
242
+ raw.ref ? { ref: raw.ref } : ctx
243
+ );
164
244
  continue;
165
245
  }
166
- if (isRepeaterArray(raw)) {
167
- out[key] = { value: envelopeRepeaterItems(raw, path), name: path };
246
+ if (isRecordList(raw)) {
247
+ const owner = ctx.owners?.(key);
248
+ out[key] = { value: envelopeListRows(raw, owner), name: path };
168
249
  continue;
169
250
  }
170
251
  if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
171
- out[key] = toFieldEnvelopes(raw, path);
252
+ out[key] = toFieldEnvelopes(raw, path, ctx);
172
253
  continue;
173
254
  }
174
- out[key] = { value: emptyValue(raw), name: path };
255
+ out[key] = withLeaf({ value: emptyValue(raw), name: path }, ctx);
175
256
  }
176
257
  return brandFields(out);
177
258
  }
178
- function envelopeRepeaterItems(items, prefix) {
179
- return items.map((item, i) => {
180
- const path = joinPath(prefix, String(i));
181
- if (isBrandedFields(item)) return item;
182
- if (item && typeof item === "object" && !Array.isArray(item)) {
183
- return toFieldEnvelopes(item, path);
184
- }
185
- return toFieldEnvelopes({}, path);
259
+ function envelopeListRows(items, owner) {
260
+ return items.map((item) => envelopeListRow(item, owner));
261
+ }
262
+ function envelopeListRow(item, owner) {
263
+ if (isBrandedFields(item) && typeof item.id === "string") {
264
+ return item;
265
+ }
266
+ const raw = item && typeof item === "object" && !Array.isArray(item) ? item : {};
267
+ const id = rowId(raw);
268
+ const ref = isListOwner(owner) && id ? { providerId: owner.providerId, entity: owner.entity, id } : void 0;
269
+ const fields = toFieldEnvelopes(raw, "", {
270
+ ref,
271
+ readOnly: !ref
186
272
  });
273
+ const row = fields;
274
+ if (typeof row.id !== "string") {
275
+ row.id = id;
276
+ }
277
+ return row;
187
278
  }
188
- function attachFieldEnvelopes(props) {
279
+ function attachFieldEnvelopes(props, sources) {
189
280
  const raw = props && typeof props === "object" ? { ...props } : {};
190
281
  if (isBrandedFields(raw.fields)) return raw;
191
282
  const { fields: existing, ...content } = raw;
192
283
  const source = existing && typeof existing === "object" && !isFieldEnvelope(existing) ? existing : content;
193
- return { ...raw, fields: toFieldEnvelopes(source) };
284
+ return {
285
+ ...raw,
286
+ fields: toFieldEnvelopes(source, "", {
287
+ owners: (fieldName) => listOwnerForField(fieldName, source, sources)
288
+ })
289
+ };
194
290
  }
195
291
  function walkLayoutNodes(nodes) {
196
292
  if (!Array.isArray(nodes)) return;
197
293
  for (const node of nodes) {
198
294
  if (!node || typeof node !== "object") continue;
199
295
  const rec = node;
200
- rec.props = attachFieldEnvelopes(rec.props);
296
+ rec.props = attachFieldEnvelopes(rec.props, {
297
+ connections: rec.resources,
298
+ reads: rec.reads
299
+ });
201
300
  for (const slot of rec.slots || []) {
202
301
  walkLayoutNodes(slot.children);
203
302
  }
@@ -314,7 +413,10 @@ async function fetchEdgeResolve(options) {
314
413
  return envelopeResolvedPayload(body);
315
414
  }
316
415
  function envelopeResolvedComponent(node) {
317
- node.props = attachFieldEnvelopes(node.props);
416
+ node.props = attachFieldEnvelopes(node.props, {
417
+ connections: node.resources,
418
+ reads: node.reads
419
+ });
318
420
  if (!node.children) return;
319
421
  for (const kids of Object.values(node.children)) {
320
422
  for (const child of kids || []) envelopeResolvedComponent(child);
@@ -608,7 +710,7 @@ async function fetchEdgeQuery(options) {
608
710
  async function queryContent(options) {
609
711
  const target = resolveAmplifyUpTarget({ configTarget: options.target });
610
712
  const { edgeUrl } = resolveAmplifyUpUrls(target);
611
- return fetchEdgeQuery({
713
+ const raw = await fetchEdgeQuery({
612
714
  edgeUrl,
613
715
  trackingId: options.trackingId,
614
716
  route: options.route,
@@ -617,6 +719,13 @@ async function queryContent(options) {
617
719
  fetch: options.fetch,
618
720
  signal: options.signal
619
721
  });
722
+ return {
723
+ ...raw,
724
+ results: envelopeListRows(
725
+ raw.results,
726
+ listOwnerFromSpec(options.spec)
727
+ )
728
+ };
620
729
  }
621
730
  function nextPageSpec(pagination) {
622
731
  return { ...pagination.spec, offset: pagination.nextOffset };