@aws-amplify/data-schema 0.16.2 → 0.17.1

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 (39) hide show
  1. package/dist/cjs/SchemaProcessor.js +6 -6
  2. package/dist/cjs/SchemaProcessor.js.map +1 -1
  3. package/dist/cjs/runtime/internals/operations/custom.js +33 -5
  4. package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
  5. package/dist/cjs/runtime/internals/operations/get.js +36 -6
  6. package/dist/cjs/runtime/internals/operations/get.js.map +1 -1
  7. package/dist/cjs/runtime/internals/operations/indexQuery.js +39 -11
  8. package/dist/cjs/runtime/internals/operations/indexQuery.js.map +1 -1
  9. package/dist/cjs/runtime/internals/operations/list.js +50 -6
  10. package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
  11. package/dist/cjs/runtime/internals/operations/utils.js +42 -0
  12. package/dist/cjs/runtime/internals/operations/utils.js.map +1 -0
  13. package/dist/esm/Authorization.d.ts +2 -2
  14. package/dist/esm/MappedTypes/MapSecondaryIndexes.d.ts +2 -2
  15. package/dist/esm/ModelRelationalField.d.ts +1 -1
  16. package/dist/esm/SchemaProcessor.mjs +6 -6
  17. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  18. package/dist/esm/runtime/client/index.d.ts +20 -21
  19. package/dist/esm/runtime/internals/operations/custom.mjs +33 -5
  20. package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
  21. package/dist/esm/runtime/internals/operations/get.mjs +36 -6
  22. package/dist/esm/runtime/internals/operations/get.mjs.map +1 -1
  23. package/dist/esm/runtime/internals/operations/indexQuery.mjs +39 -11
  24. package/dist/esm/runtime/internals/operations/indexQuery.mjs.map +1 -1
  25. package/dist/esm/runtime/internals/operations/list.mjs +50 -6
  26. package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
  27. package/dist/esm/runtime/internals/operations/utils.d.ts +8 -0
  28. package/dist/esm/runtime/internals/operations/utils.mjs +38 -0
  29. package/dist/esm/runtime/internals/operations/utils.mjs.map +1 -0
  30. package/dist/meta/cjs.tsbuildinfo +1 -1
  31. package/package.json +1 -1
  32. package/src/MappedTypes/MapSecondaryIndexes.ts +22 -26
  33. package/src/SchemaProcessor.ts +6 -1
  34. package/src/runtime/client/index.ts +34 -11
  35. package/src/runtime/internals/operations/custom.ts +44 -5
  36. package/src/runtime/internals/operations/get.ts +47 -7
  37. package/src/runtime/internals/operations/indexQuery.ts +43 -11
  38. package/src/runtime/internals/operations/list.ts +63 -7
  39. package/src/runtime/internals/operations/utils.ts +35 -0
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getFactory = void 0;
5
5
  const APIClient_1 = require("../APIClient");
6
+ const utils_1 = require("./utils");
6
7
  function getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {
7
8
  const getWithContext = async (contextSpec, arg, options) => {
8
9
  return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);
@@ -17,8 +18,8 @@ async function _get(client, modelIntrospection, model, arg, options, operation,
17
18
  const { name } = model;
18
19
  const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, operation, options);
19
20
  const variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);
21
+ const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);
20
22
  try {
21
- const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);
22
23
  const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);
23
24
  const { data, extensions } = context
24
25
  ? (await client.graphql(context, {
@@ -49,13 +50,42 @@ async function _get(client, modelIntrospection, model, arg, options, operation,
49
50
  }
50
51
  }
51
52
  catch (error) {
52
- if (error.errors) {
53
- // graphql errors pass through
54
- return error;
53
+ /**
54
+ * The `data` type returned by `error` here could be:
55
+ * 1) `null`
56
+ * 2) an empty object
57
+ * 3) "populated" but with a `null` value `{ getPost: null }`
58
+ * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
59
+ */
60
+ const { data, errors } = error;
61
+ /**
62
+ * `data` is not `null`, and is not an empty object:
63
+ */
64
+ if (data && Object.keys(data).length !== 0 && errors) {
65
+ const [key] = Object.keys(data);
66
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
67
+ /**
68
+ * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
69
+ * if `flattenedResult`, result is an actual record:
70
+ */
71
+ if (flattenedResult) {
72
+ if (options?.selectionSet) {
73
+ return { data: flattenedResult, errors };
74
+ }
75
+ else {
76
+ // TODO: refactor to avoid destructuring here
77
+ const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
78
+ return { data: initialized, errors };
79
+ }
80
+ }
81
+ else {
82
+ // was `data: { getPost: null }`)
83
+ return (0, utils_1.handleSingularGraphQlError)(error);
84
+ }
55
85
  }
56
86
  else {
57
- // non-graphql errors re re-thrown
58
- throw error;
87
+ // `data` is `null`:
88
+ return (0, utils_1.handleSingularGraphQlError)(error);
59
89
  }
60
90
  }
61
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get.js","sources":["../../../../../src/runtime/internals/operations/get.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nfunction getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {\n const getWithContext = async (contextSpec, arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);\n };\n const get = async (arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals);\n };\n return useContext ? getWithContext : get;\n}\nexports.getFactory = getFactory;\nasync function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, operation, options);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);\n try {\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);\n return { data: initialized, extensions };\n }\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;AAC5B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,KAAK,EAAE;AACpG,IAAI,MAAM,cAAc,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAChE,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AAC3G,KAAK,CAAC;AACN,IAAI,MAAM,GAAG,GAAG,OAAO,GAAG,EAAE,OAAO,KAAK;AACxC,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,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AACA,QAAQ,IAAI,IAAI,EAAE;AAClB,YAAY,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5C,YAAY,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7E,YAAY,IAAI,OAAO,EAAE,YAAY,EAAE;AACvC,gBAAgB,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC;AAC7D,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AACtK,gBAAgB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACzD,aAAa;AACb,SAAS;AACT,aAAa;AACb,YAAY,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9C,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B;AACA,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,aAAa;AACb;AACA,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;"}
1
+ {"version":3,"file":"get.js","sources":["../../../../../src/runtime/internals/operations/get.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\nfunction getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {\n const getWithContext = async (contextSpec, arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);\n };\n const get = async (arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals);\n };\n return useContext ? getWithContext : get;\n}\nexports.getFactory = getFactory;\nasync function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, operation, options);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);\n try {\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);\n return { data: initialized, extensions };\n }\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n /**\n * The `data` type returned by `error` here could be:\n * 1) `null`\n * 2) an empty object\n * 3) \"populated\" but with a `null` value `{ getPost: null }`\n * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`\n */\n const { data, errors } = error;\n /**\n * `data` is not `null`, and is not an empty object:\n */\n if (data && Object.keys(data).length !== 0 && errors) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n /**\n * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)\n * if `flattenedResult`, result is an actual record:\n */\n if (flattenedResult) {\n if (options?.selectionSet) {\n return { data: flattenedResult, errors };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);\n return { data: initialized, errors };\n }\n }\n else {\n // was `data: { getPost: null }`)\n return (0, utils_1.handleSingularGraphQlError)(error);\n }\n }\n else {\n // `data` is `null`:\n return (0, utils_1.handleSingularGraphQlError)(error);\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;AAC5B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,KAAK,EAAE;AACpG,IAAI,MAAM,cAAc,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAChE,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AAC3G,KAAK,CAAC;AACN,IAAI,MAAM,GAAG,GAAG,OAAO,GAAG,EAAE,OAAO,KAAK;AACxC,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAC9F,KAAK,CAAC;AACN,IAAI,OAAO,UAAU,GAAG,cAAc,GAAG,GAAG,CAAC;AAC7C,CAAC;AACD,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;AAChC,eAAe,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE;AAC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kB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AAC1K,oBAAoB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACzD,iBAAiB;AACjB,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,OAAO,IAAI,OAAO,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AACtE,aAAa;AACb,SAAS;AACT,aAAa;AACb;AACA,YAAY,OAAO,IAAI,OAAO,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AAClE,SAAS;AACT,KAAK;AACL;;"}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.indexQueryFactory = void 0;
5
5
  const APIClient_1 = require("../APIClient");
6
+ const utils_1 = require("./utils");
6
7
  function indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {
7
8
  const indexQueryWithContext = async (contextSpec, args, options) => {
8
9
  return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {
@@ -36,16 +37,6 @@ function processGraphQlResponse(result, selectionSet, modelInitializer) {
36
37
  extensions,
37
38
  };
38
39
  }
39
- function handleGraphQlError(error) {
40
- if (error.errors) {
41
- // graphql errors pass through
42
- return error;
43
- }
44
- else {
45
- // non-graphql errors re re-thrown
46
- throw error;
47
- }
48
- }
49
40
  async function _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {
50
41
  const { name } = model;
51
42
  const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);
@@ -69,7 +60,44 @@ async function _indexQuery(client, modelIntrospection, model, indexMeta, getInte
69
60
  }
70
61
  }
71
62
  catch (error) {
72
- return handleGraphQlError(error);
63
+ /**
64
+ * The `data` type returned by `error` here could be:
65
+ * 1) `null`
66
+ * 2) an empty object
67
+ * 3) "populated" but with a `null` value:
68
+ * `data: { listByExampleId: null }`
69
+ * 4) an actual record:
70
+ * `data: { listByExampleId: items: [{ id: '1', ...etc } }]`
71
+ */
72
+ const { data, errors } = error;
73
+ // `data` is not `null`, and is not an empty object:
74
+ if (data !== undefined && Object.keys(data).length !== 0 && errors) {
75
+ const [key] = Object.keys(data);
76
+ if (data[key]?.items) {
77
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
78
+ /**
79
+ * Check exists since `flattenedResult` could be `null`.
80
+ * if `flattenedResult` exists, result is an actual record.
81
+ */
82
+ if (flattenedResult) {
83
+ return {
84
+ data: args?.selectionSet
85
+ ? flattenedResult
86
+ : modelInitializer(flattenedResult),
87
+ nextToken: data[key]?.nextToken,
88
+ };
89
+ }
90
+ }
91
+ // response is of type `data: { listByExampleId: null }`
92
+ return {
93
+ data: data[key],
94
+ nextToken: data[key]?.nextToken,
95
+ };
96
+ }
97
+ else {
98
+ // `data` is `null` or an empty object:
99
+ return (0, utils_1.handleListGraphQlError)(error);
100
+ }
73
101
  }
74
102
  }
75
103
  //# sourceMappingURL=indexQuery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"indexQuery.js","sources":["../../../../../src/runtime/internals/operations/indexQuery.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.indexQueryFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nfunction indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {\n const indexQueryWithContext = async (contextSpec, args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n }, contextSpec);\n };\n const indexQuery = async (args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n });\n };\n return context ? indexQueryWithContext : indexQuery;\n}\nexports.indexQueryFactory = indexQueryFactory;\nfunction processGraphQlResponse(result, selectionSet, modelInitializer) {\n const { data, extensions } = result;\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n return {\n data: selectionSet ? flattenedResult : modelInitializer(flattenedResult),\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n}\nfunction handleGraphQlError(error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n}\nasync function _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'INDEX_QUERY', args, modelIntrospection, indexMeta);\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);\n const modelInitializer = (flattenedResult) => (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n try {\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);\n const graphQlParams = {\n ...auth,\n query,\n variables,\n };\n const requestArgs = [graphQlParams, headers];\n if (contextSpec !== undefined) {\n requestArgs.unshift(contextSpec);\n }\n const response = (await client.graphql(...requestArgs));\n if (response.data !== undefined) {\n return processGraphQlResponse(response, args?.selectionSet, modelInitializer);\n }\n }\n catch (error) {\n return handleGraphQlError(error);\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iBAAiB,GAAG,KAAK,CAAC,CAAC;AACnC,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,SAAS,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AACxG,IAAI,MAAM,qBAAqB,GAAG,OAAO,WAAW,E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G,IAAI;AACnB,YAAY,KAAK;AACjB,YAAY,SAAS;AACrB,SAAS,CAAC;AACV,QAAQ,MAAM,WAAW,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AACrD,QAAQ,IAAI,WAAW,KAAK,SAAS,EAAE;AACvC,YAAY,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAC7C,SAAS;AACT,QAAQ,MAAM,QAAQ,IAAI,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;AAChE,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE;AACzC,YAAY,OAAO,sBAAsB,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAAC;AAC1F,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACzC,KAAK;AACL;;"}
1
+ {"version":3,"file":"indexQuery.js","sources":["../../../../../src/runtime/internals/operations/indexQuery.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.indexQueryFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\nfunction indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {\n const indexQueryWithContext = async (contextSpec, args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n }, contextSpec);\n };\n const indexQuery = async (args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n });\n };\n return context ? indexQueryWithContext : indexQuery;\n}\nexports.indexQueryFactory = indexQueryFactory;\nfunction processGraphQlResponse(result, selectionSet, modelInitializer) {\n const { data, extensions } = result;\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n return {\n data: selectionSet ? flattenedResult : modelInitializer(flattenedResult),\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n}\nasync function _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'INDEX_QUERY', args, modelIntrospection, indexMeta);\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);\n const modelInitializer = (flattenedResult) => (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n try {\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);\n const graphQlParams = {\n ...auth,\n query,\n variables,\n };\n const requestArgs = [graphQlParams, headers];\n if (contextSpec !== undefined) {\n requestArgs.unshift(contextSpec);\n }\n const response = (await client.graphql(...requestArgs));\n if (response.data !== undefined) {\n return processGraphQlResponse(response, args?.selectionSet, modelInitializer);\n }\n }\n catch (error) {\n /**\n * The `data` type returned by `error` here could be:\n * 1) `null`\n * 2) an empty object\n * 3) \"populated\" but with a `null` value:\n * `data: { listByExampleId: null }`\n * 4) an actual record:\n * `data: { listByExampleId: items: [{ id: '1', ...etc } }]`\n */\n const { data, errors } = error;\n // `data` is not `null`, and is not an empty object:\n if (data !== undefined && Object.keys(data).length !== 0 && errors) {\n const [key] = Object.keys(data);\n if (data[key]?.items) {\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n /**\n * Check exists since `flattenedResult` could be `null`.\n * if `flattenedResult` exists, result is an actual record.\n */\n if (flattenedResult) {\n return {\n data: args?.selectionSet\n ? flattenedResult\n : modelInitializer(flattenedResult),\n nextToken: data[key]?.nextToken,\n };\n }\n }\n // response is of type `data: { listByExampleId: null }`\n return {\n data: data[key],\n nextToken: data[key]?.nextToken,\n };\n }\n else {\n // `data` is `null` or an emp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I,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AACjF;AACA;AACA;AACA;AACA,gBAAgB,IAAI,eAAe,EAAE;AACrC,oBAAoB,OAAO;AAC3B,wBAAwB,IAAI,EAAE,IAAI,EAAE,YAAY;AAChD,8BAA8B,eAAe;AAC7C,8BAA8B,gBAAgB,CAAC,eAAe,CAAC;AAC/D,wBAAwB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AACvD,qBAAqB,CAAC;AACtB,iBAAiB;AACjB,aAAa;AACb;AACA,YAAY,OAAO;AACnB,gBAAgB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC/B,gBAAgB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AAC/C,aAAa,CAAC;AACd,SAAS;AACT,aAAa;AACb;AACA,YAAY,OAAO,IAAI,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC9D,SAAS;AACT,KAAK;AACL;;"}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.listFactory = void 0;
5
5
  const APIClient_1 = require("../APIClient");
6
+ const utils_1 = require("./utils");
6
7
  function listFactory(client, modelIntrospection, model, getInternals, context = false) {
7
8
  const listWithContext = async (contextSpec, args) => {
8
9
  return _list(client, modelIntrospection, model, getInternals, args, contextSpec);
@@ -17,8 +18,8 @@ async function _list(client, modelIntrospection, model, getInternals, args, cont
17
18
  const { name } = model;
18
19
  const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'LIST', args);
19
20
  const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);
21
+ const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);
20
22
  try {
21
- const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);
22
23
  const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);
23
24
  const { data, extensions } = contextSpec
24
25
  ? (await client.graphql(contextSpec, {
@@ -61,13 +62,56 @@ async function _list(client, modelIntrospection, model, getInternals, args, cont
61
62
  }
62
63
  }
63
64
  catch (error) {
64
- if (error.errors) {
65
- // graphql errors pass through
66
- return error;
65
+ /**
66
+ * The `data` type returned by `error` here could be:
67
+ * 1) `null`
68
+ * 2) an empty object
69
+ * 3) "populated" but with a `null` value `data: { listPosts: null }`
70
+ * 4) actual records `data: { listPosts: items: [{ id: '1', ...etc }] }`
71
+ */
72
+ const { data, errors } = error;
73
+ // `data` is not `null`, and is not an empty object:
74
+ if (data !== undefined && Object.keys(data).length !== 0 && errors) {
75
+ const [key] = Object.keys(data);
76
+ if (data[key]?.items) {
77
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
78
+ /**
79
+ * Check exists since `flattenedResult` could be `null`.
80
+ * if `flattenedResult` exists, result is an actual record.
81
+ */
82
+ if (flattenedResult) {
83
+ // don't init if custom selection set
84
+ if (args?.selectionSet) {
85
+ return {
86
+ data: flattenedResult,
87
+ nextToken: data[key]?.nextToken,
88
+ errors,
89
+ };
90
+ }
91
+ else {
92
+ const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
93
+ // data is full record w/out selection set:
94
+ return {
95
+ data: initialized,
96
+ nextToken: data[key]?.nextToken,
97
+ errors,
98
+ };
99
+ }
100
+ }
101
+ return {
102
+ data: data[key],
103
+ nextToken: data[key]?.nextToken,
104
+ errors,
105
+ };
106
+ }
107
+ else {
108
+ // response is of type `data: { getPost: null }`)
109
+ return (0, utils_1.handleListGraphQlError)(error);
110
+ }
67
111
  }
68
112
  else {
69
- // non-graphql errors re re-thrown
70
- throw error;
113
+ // `data` is `null` or an empty object:
114
+ return (0, utils_1.handleListGraphQlError)(error);
71
115
  }
72
116
  }
73
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","sources":["../../../../../src/runtime/internals/operations/list.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.listFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nfunction listFactory(client, modelIntrospection, model, getInternals, context = false) {\n const listWithContext = async (contextSpec, args) => {\n return _list(client, modelIntrospection, model, getInternals, args, contextSpec);\n };\n const list = async (args) => {\n return _list(client, modelIntrospection, model, getInternals, args);\n };\n return context ? listWithContext : list;\n}\nexports.listFactory = listFactory;\nasync function _list(client, modelIntrospection, model, getInternals, args, contextSpec) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'LIST', args);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);\n try {\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);\n const { data, extensions } = contextSpec\n ? (await client.graphql(contextSpec, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data !== undefined) {\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n // don't init if custom selection set\n if (args?.selectionSet) {\n return {\n data: flattenedResult,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n else {\n const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n return {\n data: initialized,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC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AS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AACtD,wBAAwB,UAAU;AAClC,qBAAqB,CAAC;AACtB,iBAAiB;AACjB,aAAa;AACb,YAAY,OAAO;AACnB,gBAAgB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC/B,gBAAgB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AAC9C,gBAAgB,UAAU;AAC1B,aAAa,CAAC;AACd,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B;AACA,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,aAAa;AACb;AACA,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;"}
1
+ {"version":3,"file":"list.js","sources":["../../../../../src/runtime/internals/operations/list.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.listFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\nfunction listFactory(client, modelIntrospection, model, getInternals, context = false) {\n const listWithContext = async (contextSpec, args) => {\n return _list(client, modelIntrospection, model, getInternals, args, contextSpec);\n };\n const list = async (args) => {\n return _list(client, modelIntrospection, model, getInternals, args);\n };\n return context ? listWithContext : list;\n}\nexports.listFactory = listFactory;\nasync function _list(client, modelIntrospection, model, getInternals, args, contextSpec) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'LIST', args);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);\n try {\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);\n const { data, extensions } = contextSpec\n ? (await client.graphql(contextSpec, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data !== undefined) {\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n // don't init if custom selection set\n if (args?.selectionSet) {\n return {\n data: flattenedResult,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n else {\n const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n return {\n data: initialized,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n catch (error) {\n /**\n * The `data` type returned by `error` here could be:\n * 1) `null`\n * 2) an empty object\n * 3) \"populated\" but with a `null` value `data: { listPosts: null }`\n * 4) actual records `data: { listPosts: items: [{ id: '1', ...etc }] }`\n */\n const { data, errors } = error;\n // `data` is not `null`, and is not an empty object:\n if (data !== undefined && Object.keys(data).length !== 0 && errors) {\n const [key] = Object.keys(data);\n if (data[key]?.items) {\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n /**\n * Check exists since `flattenedResult` could be `null`.\n * if `flattenedResult` exists, result is an actual record.\n */\n if (flattenedResult) {\n // don't init if custom selection set\n if (args?.selectionSet) {\n return {\n data: flattenedResult,\n nextToken: data[key]?.nextToken,\n errors,\n };\n }\n else {\n const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n // data is full record w/out selection set:\n return {\n data: initialized,\n nextToken: data[key]?.nextToken,\n errors,\n };\n }\n }\n return {\n data: data[key],\n nextToken: data[key]?.nextToken,\n errors,\n };\n }\n else {\n // response is of type `data: { getPost: null }`)\n return (0, utils_1.handleListGraphQlError)(error);\n }\n }\n else {\n // `data` is `null` or an empty object:\n return (0, utils_1.handleListGraphQlError)(error);\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IA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GAAG,IAAI,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;AAC9K;AACA,wBAAwB,OAAO;AAC/B,4BAA4B,IAAI,EAAE,WAAW;AAC7C,4BAA4B,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AAC3D,4BAA4B,MAAM;AAClC,yBAAyB,CAAC;AAC1B,qBAAqB;AACrB,iBAAiB;AACjB,gBAAgB,OAAO;AACvB,oBAAoB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AACnC,oBAAoB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AACnD,oBAAoB,MAAM;AAC1B,iBAAiB,CAAC;AAClB,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,OAAO,IAAI,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAClE,aAAa;AACb,SAAS;AACT,aAAa;AACb;AACA,YAAY,OAAO,IAAI,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC9D,SAAS;AACT,KAAK;AACL;;"}
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ // import { GraphQLFormattedError } from '@aws-amplify/data-schema-types';
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.handleSingularGraphQlError = exports.handleListGraphQlError = void 0;
8
+ /**
9
+ * Handle errors for list return types (list and index query operations)
10
+ */
11
+ function handleListGraphQlError(error) {
12
+ if (error?.errors) {
13
+ // graphql errors pass through
14
+ return {
15
+ ...error,
16
+ data: [],
17
+ };
18
+ }
19
+ else {
20
+ // non-graphql errors are re-thrown
21
+ throw error;
22
+ }
23
+ }
24
+ exports.handleListGraphQlError = handleListGraphQlError;
25
+ /**
26
+ * Handle errors for singular return types (create, get, update, delete operations)
27
+ */
28
+ function handleSingularGraphQlError(error) {
29
+ if (error.errors) {
30
+ // graphql errors pass through
31
+ return {
32
+ ...error,
33
+ data: null,
34
+ };
35
+ }
36
+ else {
37
+ // non-graphql errors are re-thrown
38
+ throw error;
39
+ }
40
+ }
41
+ exports.handleSingularGraphQlError = handleSingularGraphQlError;
42
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../../src/runtime/internals/operations/utils.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n// import { GraphQLFormattedError } from '@aws-amplify/data-schema-types';\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.handleSingularGraphQlError = exports.handleListGraphQlError = void 0;\n/**\n * Handle errors for list return types (list and index query operations)\n */\nfunction handleListGraphQlError(error) {\n if (error?.errors) {\n // graphql errors pass through\n return {\n ...error,\n data: [],\n };\n }\n else {\n // non-graphql errors are re-thrown\n throw error;\n }\n}\nexports.handleListGraphQlError = handleListGraphQlError;\n/**\n * Handle errors for singular return types (create, get, update, delete operations)\n */\nfunction handleSingularGraphQlError(error) {\n if (error.errors) {\n // graphql errors pass through\n return {\n ...error,\n data: null,\n };\n }\n else {\n // non-graphql errors are re-thrown\n throw error;\n }\n}\nexports.handleSingularGraphQlError = handleSingularGraphQlError;\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0BAA0B,GAAG,OAAO,CAAC,sBAAsB,GAAG,KAAK,CAAC,CAAC;AAC7E;AACA;AACA;AACA,SAAS,sBAAsB,CAAC,KAAK,EAAE;AACvC,IAAI,IAAI,KAAK,EAAE,MAAM,EAAE;AACvB;AACA,QAAQ,OAAO;AACf,YAAY,GAAG,KAAK;AACpB,YAAY,IAAI,EAAE,EAAE;AACpB,SAAS,CAAC;AACV,KAAK;AACL,SAAS;AACT;AACA,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;AACxD;AACA;AACA;AACA,SAAS,0BAA0B,CAAC,KAAK,EAAE;AAC3C,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE;AACtB;AACA,QAAQ,OAAO;AACf,YAAY,GAAG,KAAK;AACpB,YAAY,IAAI,EAAE,IAAI;AACtB,SAAS,CAAC;AACV,KAAK;AACL,SAAS;AACT;AACA,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,0BAA0B,GAAG,0BAA0B;;"}
@@ -347,8 +347,8 @@ export type ImpliedAuthField<T extends Authorization<any, any, any>> = T extends
347
347
  export type ImpliedAuthFields<T extends Authorization<any, any, any>> = ImpliedAuthField<T> extends never ? never : UnionToIntersection<ImpliedAuthField<T>>;
348
348
  export declare const accessData: <T extends Authorization<any, any, any>>(authorization: T) => {
349
349
  strategy?: any;
350
- provider?: "function" | "apiKey" | "iam" | "userPools" | "oidc" | undefined;
351
- operations?: ("create" | "update" | "delete" | "read" | "get" | "list" | "sync" | "listen" | "search")[] | undefined;
350
+ provider?: "function" | "apiKey" | "iam" | "oidc" | "userPools" | undefined;
351
+ operations?: ("create" | "get" | "update" | "delete" | "list" | "search" | "read" | "sync" | "listen")[] | undefined;
352
352
  groupOrOwnerField?: any;
353
353
  groups?: string[] | undefined;
354
354
  multiOwner: any;
@@ -1,4 +1,3 @@
1
- import { IsEmptyStringOrNever } from '@aws-amplify/data-schema-types';
2
1
  import { ModelIndexType } from '../ModelIndex';
3
2
  type ModelIndexTypeShape = ModelIndexType<any, any, any, any, any>;
4
3
  /**
@@ -25,7 +24,8 @@ export type SecondaryIndexToIR<Idxs extends ReadonlyArray<ModelIndexTypeShape>,
25
24
  * @remarks - the IR type alias is defined as SecondaryIndexIrShape in data-schema-types
26
25
  */
27
26
  type SingleIndexIrFromType<Idx extends ModelIndexTypeShape, ResolvedFields> = Idx extends ModelIndexType<any, infer PK extends string, infer SK, infer QueryField extends string | never, any> ? {
28
- queryField: IsEmptyStringOrNever<QueryField> extends true ? `listBy${QueryFieldLabelFromTuple<SK, Capitalize<PK>>}` : QueryField;
27
+ defaultQueryFieldSuffix: `${QueryFieldLabelFromTuple<SK, Capitalize<PK>>}`;
28
+ queryField: QueryField;
29
29
  pk: PK extends keyof ResolvedFields ? {
30
30
  [Key in PK]: Exclude<ResolvedFields[PK], null>;
31
31
  } : never;
@@ -93,5 +93,5 @@ export declare function hasMany<RM extends string>(relatedModel: RM, references:
93
93
  * @param relatedModel name of the related `.hasOne()` or `.hasMany()` model
94
94
  * @returns a belong-to relationship definition
95
95
  */
96
- export declare function belongsTo<RM extends string>(relatedModel: RM, references: string | string[]): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.belongsTo, false>, RM, "valueRequired" | "arrayRequired" | "required", undefined>;
96
+ export declare function belongsTo<RM extends string>(relatedModel: RM, references: string | string[]): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.belongsTo, false>, RM, "required" | "valueRequired" | "arrayRequired", undefined>;
97
97
  export {};
@@ -538,19 +538,19 @@ function processFields(typeName, fields, impliedFields, fieldLevelAuthRules, ide
538
538
  * @param sk - (optional) array of sort key field names
539
539
  * @returns default query field name
540
540
  */
541
- const secondaryIndexDefaultQueryField = (pk, sk) => {
541
+ const secondaryIndexDefaultQueryField = (modelName, pk, sk) => {
542
542
  const skName = sk?.length ? 'And' + sk?.map(capitalize).join('And') : '';
543
- const queryField = `listBy${capitalize(pk)}${skName}`;
543
+ const queryField = `list${capitalize(modelName)}By${capitalize(pk)}${skName}`;
544
544
  return queryField;
545
545
  };
546
546
  /**
547
547
  * Given InternalModelIndexType[] returns a map where the key is the model field to be annotated with an @index directive
548
548
  * and the value is an array of transformed Amplify @index directives with all supplied attributes
549
549
  */
550
- const transformedSecondaryIndexesForModel = (secondaryIndexes) => {
550
+ const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes) => {
551
551
  const indexDirectiveWithAttributes = (partitionKey, sortKeys, indexName, queryField) => {
552
552
  if (!sortKeys.length && !indexName && !queryField) {
553
- return `@index(queryField: "${secondaryIndexDefaultQueryField(partitionKey)}")`;
553
+ return `@index(queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey)}")`;
554
554
  }
555
555
  const attributes = [];
556
556
  if (indexName) {
@@ -563,7 +563,7 @@ const transformedSecondaryIndexesForModel = (secondaryIndexes) => {
563
563
  attributes.push(`queryField: "${queryField}"`);
564
564
  }
565
565
  else {
566
- attributes.push(`queryField: "${secondaryIndexDefaultQueryField(partitionKey, sortKeys)}"`);
566
+ attributes.push(`queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey, sortKeys)}"`);
567
567
  }
568
568
  return `@index(${attributes.join(', ')})`;
569
569
  };
@@ -719,7 +719,7 @@ const schemaPreprocessor = (schema) => {
719
719
  const fields = typeDef.data.fields;
720
720
  const identifier = typeDef.data.identifier;
721
721
  const [partitionKey] = identifier;
722
- const transformedSecondaryIndexes = transformedSecondaryIndexesForModel(typeDef.data.secondaryIndexes);
722
+ const transformedSecondaryIndexes = transformedSecondaryIndexesForModel(typeName, typeDef.data.secondaryIndexes);
723
723
  const { authString, authFields } = calculateAuth(mostRelevantAuthRules);
724
724
  if (authString == '') {
725
725
  throw new Error(`Model \`${typeName}\` is missing authorization rules. Add global rules to the schema or ensure every model has its own rules.`);