@aws-amplify/api-graphql 4.0.1 → 4.0.2-unstable.b778a9e.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.
Files changed (110) hide show
  1. package/dist/cjs/internals/APIClient.js +503 -0
  2. package/dist/cjs/internals/APIClient.js.map +1 -0
  3. package/dist/cjs/internals/InternalGraphQLAPI.js +1 -1
  4. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  5. package/dist/cjs/internals/generateClient.js +33 -0
  6. package/dist/cjs/internals/generateClient.js.map +1 -0
  7. package/dist/cjs/internals/generateModelsProperty.js +43 -0
  8. package/dist/cjs/internals/generateModelsProperty.js.map +1 -0
  9. package/dist/cjs/internals/index.js +3 -1
  10. package/dist/cjs/internals/index.js.map +1 -1
  11. package/dist/cjs/internals/operations/get.js +61 -0
  12. package/dist/cjs/internals/operations/get.js.map +1 -0
  13. package/dist/cjs/internals/operations/list.js +73 -0
  14. package/dist/cjs/internals/operations/list.js.map +1 -0
  15. package/dist/cjs/internals/operations/observeQuery.js +121 -0
  16. package/dist/cjs/internals/operations/observeQuery.js.map +1 -0
  17. package/dist/cjs/internals/operations/subscription.js +29 -0
  18. package/dist/cjs/internals/operations/subscription.js.map +1 -0
  19. package/dist/cjs/internals/server/generateClient.js +32 -0
  20. package/dist/cjs/internals/server/generateClient.js.map +1 -0
  21. package/dist/cjs/internals/server/generateModelsProperty.js +47 -0
  22. package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -0
  23. package/dist/cjs/internals/server/index.js +9 -0
  24. package/dist/cjs/internals/server/index.js.map +1 -0
  25. package/dist/cjs/internals/types.js +4 -0
  26. package/dist/cjs/internals/types.js.map +1 -0
  27. package/dist/cjs/types/index.js +3 -1
  28. package/dist/cjs/types/index.js.map +1 -1
  29. package/dist/cjs/utils/findIndexByFields.js +25 -0
  30. package/dist/cjs/utils/findIndexByFields.js.map +1 -0
  31. package/dist/cjs/utils/index.js +5 -1
  32. package/dist/cjs/utils/index.js.map +1 -1
  33. package/dist/cjs/utils/resolveOwnerFields.js +42 -0
  34. package/dist/cjs/utils/resolveOwnerFields.js.map +1 -0
  35. package/dist/cjs/utils/resolvePKFields.js +17 -0
  36. package/dist/cjs/utils/resolvePKFields.js.map +1 -0
  37. package/dist/esm/index.mjs +1 -1
  38. package/dist/esm/internals/APIClient.d.ts +121 -0
  39. package/dist/esm/internals/APIClient.mjs +493 -0
  40. package/dist/esm/internals/APIClient.mjs.map +1 -0
  41. package/dist/esm/internals/InternalGraphQLAPI.mjs +1 -1
  42. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  43. package/dist/esm/internals/generateClient.d.ts +12 -0
  44. package/dist/esm/internals/generateClient.mjs +31 -0
  45. package/dist/esm/internals/generateClient.mjs.map +1 -0
  46. package/dist/esm/internals/generateModelsProperty.d.ts +4 -0
  47. package/dist/esm/internals/generateModelsProperty.mjs +41 -0
  48. package/dist/esm/internals/generateModelsProperty.mjs.map +1 -0
  49. package/dist/esm/internals/index.d.ts +1 -0
  50. package/dist/esm/internals/index.mjs +1 -0
  51. package/dist/esm/internals/index.mjs.map +1 -1
  52. package/dist/esm/internals/operations/get.d.ts +2 -0
  53. package/dist/esm/internals/operations/get.mjs +59 -0
  54. package/dist/esm/internals/operations/get.mjs.map +1 -0
  55. package/dist/esm/internals/operations/list.d.ts +2 -0
  56. package/dist/esm/internals/operations/list.mjs +71 -0
  57. package/dist/esm/internals/operations/list.mjs.map +1 -0
  58. package/dist/esm/internals/operations/observeQuery.d.ts +2 -0
  59. package/dist/esm/internals/operations/observeQuery.mjs +122 -0
  60. package/dist/esm/internals/operations/observeQuery.mjs.map +1 -0
  61. package/dist/esm/internals/operations/subscription.d.ts +1 -0
  62. package/dist/esm/internals/operations/subscription.mjs +27 -0
  63. package/dist/esm/internals/operations/subscription.mjs.map +1 -0
  64. package/dist/esm/internals/server/generateClient.d.ts +11 -0
  65. package/dist/esm/internals/server/generateClient.mjs +34 -0
  66. package/dist/esm/internals/server/generateClient.mjs.map +1 -0
  67. package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -0
  68. package/dist/esm/internals/server/generateModelsProperty.mjs +45 -0
  69. package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -0
  70. package/dist/esm/internals/server/index.d.ts +1 -0
  71. package/dist/esm/internals/server/index.mjs +2 -0
  72. package/dist/esm/internals/server/index.mjs.map +1 -0
  73. package/dist/esm/internals/types.d.ts +17 -0
  74. package/dist/esm/internals/types.mjs +2 -0
  75. package/dist/esm/internals/types.mjs.map +1 -0
  76. package/dist/esm/types/index.d.ts +22 -2
  77. package/dist/esm/types/index.mjs +3 -1
  78. package/dist/esm/types/index.mjs.map +1 -1
  79. package/dist/esm/utils/findIndexByFields.d.ts +9 -0
  80. package/dist/esm/utils/findIndexByFields.mjs +22 -0
  81. package/dist/esm/utils/findIndexByFields.mjs.map +1 -0
  82. package/dist/esm/utils/index.d.ts +2 -0
  83. package/dist/esm/utils/index.mjs +2 -0
  84. package/dist/esm/utils/index.mjs.map +1 -1
  85. package/dist/esm/utils/resolveOwnerFields.d.ts +12 -0
  86. package/dist/esm/utils/resolveOwnerFields.mjs +39 -0
  87. package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -0
  88. package/dist/esm/utils/resolvePKFields.d.ts +13 -0
  89. package/dist/esm/utils/resolvePKFields.mjs +14 -0
  90. package/dist/esm/utils/resolvePKFields.mjs.map +1 -0
  91. package/internals/server/package.json +8 -0
  92. package/package.json +15 -9
  93. package/src/internals/APIClient.ts +724 -0
  94. package/src/internals/InternalGraphQLAPI.ts +1 -1
  95. package/src/internals/generateClient.ts +33 -0
  96. package/src/internals/generateModelsProperty.ts +70 -0
  97. package/src/internals/index.ts +1 -0
  98. package/src/internals/operations/get.ts +121 -0
  99. package/src/internals/operations/list.ts +111 -0
  100. package/src/internals/operations/observeQuery.ts +140 -0
  101. package/src/internals/operations/subscription.ts +59 -0
  102. package/src/internals/server/generateClient.ts +45 -0
  103. package/src/internals/server/generateModelsProperty.ts +70 -0
  104. package/src/internals/server/index.ts +4 -0
  105. package/src/internals/types.ts +21 -0
  106. package/src/types/index.ts +28 -2
  107. package/src/utils/findIndexByFields.ts +29 -0
  108. package/src/utils/index.ts +2 -0
  109. package/src/utils/resolveOwnerFields.ts +65 -0
  110. package/src/utils/resolvePKFields.ts +22 -0
@@ -0,0 +1,45 @@
1
+ import { graphQLOperationsInfo } from '../APIClient.mjs';
2
+ import { listFactory } from '../operations/list.mjs';
3
+ import { getFactory } from '../operations/get.mjs';
4
+
5
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ function generateModelsProperty(client, params) {
8
+ const models = {};
9
+ const config = params.config;
10
+ const useContext = client === null;
11
+ if (!config) {
12
+ // TODO: improve
13
+ throw new Error('generateModelsProperty cannot retrieve Amplify config');
14
+ }
15
+ const modelIntrospection = config.API?.GraphQL?.modelIntrospection;
16
+ if (!modelIntrospection) {
17
+ return {};
18
+ }
19
+ const SSR_UNSUPORTED_OPS = [
20
+ 'ONCREATE',
21
+ 'ONUPDATE',
22
+ 'ONDELETE',
23
+ 'OBSERVE_QUERY',
24
+ ];
25
+ for (const model of Object.values(modelIntrospection.models)) {
26
+ const { name } = model;
27
+ models[name] = {};
28
+ Object.entries(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {
29
+ const operation = key;
30
+ // subscriptions are not supported in SSR
31
+ if (SSR_UNSUPORTED_OPS.includes(operation))
32
+ return;
33
+ if (operation === 'LIST') {
34
+ models[name][operationPrefix] = listFactory(client, modelIntrospection, model, useContext);
35
+ }
36
+ else {
37
+ models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation, useContext);
38
+ }
39
+ });
40
+ }
41
+ return models;
42
+ }
43
+
44
+ export { generateModelsProperty };
45
+ //# sourceMappingURL=generateModelsProperty.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateModelsProperty.mjs","sources":["../../../../src/internals/server/generateModelsProperty.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { graphQLOperationsInfo } from '../APIClient';\nimport { listFactory } from '../operations/list';\nimport { getFactory } from '../operations/get';\nexport function generateModelsProperty(client, params) {\n const models = {};\n const config = params.config;\n const useContext = client === null;\n if (!config) {\n // TODO: improve\n throw new Error('generateModelsProperty cannot retrieve Amplify config');\n }\n const modelIntrospection = config.API?.GraphQL?.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SSR_UNSUPORTED_OPS = [\n 'ONCREATE',\n 'ONUPDATE',\n 'ONDELETE',\n 'OBSERVE_QUERY',\n ];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n // subscriptions are not supported in SSR\n if (SSR_UNSUPORTED_OPS.includes(operation))\n return;\n if (operation === 'LIST') {\n models[name][operationPrefix] = listFactory(client, modelIntrospection, model, useContext);\n }\n else {\n models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation, useContext);\n }\n });\n }\n return models;\n}\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIO,SAAS,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE;AACvD,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC;AACtB,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AACjC,IAAI,MAAM,UAAU,GAAG,MAAM,KAAK,IAAI,CAAC;AACvC,IAAI,IAAI,CAAC,MAAM,EAAE;AACjB;AACA,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;AACjF,KAAK;AACL,IAAI,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,kBAAkB,CAAC;AACvE,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,UAAU;AAClB,QAAQ,UAAU;AAClB,QAAQ,UAAU;AAClB,QAAQ,eAAe;AACvB,KAAK,CAAC;AACN,IAAI,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE;AAClE,QAAQ,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC/B,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAC1B,QAAQ,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,eAAe,EAAE,CAAC,KAAK;AACtF,YAAY,MAAM,SAAS,GAAG,GAAG,CAAC;AAClC;AACA,YAAY,IAAI,kBAAkB,CAAC,QAAQ,CAAC,SAAS,CAAC;AACtD,gBAAgB,OAAO;AACvB,YAAY,IAAI,SAAS,KAAK,MAAM,EAAE;AACtC,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AAC3G,aAAa;AACb,iBAAiB;AACjB,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACrH,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
@@ -0,0 +1 @@
1
+ export { generateClient } from './generateClient';
@@ -0,0 +1,2 @@
1
+ export { generateClient } from './generateClient.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
3
+ /**
4
+ * @private
5
+ *
6
+ * The knobs available for configuring `generateClient` internally.
7
+ */
8
+ export type ClientGenerationParams = {
9
+ amplify: AmplifyClassV6;
10
+ } & CommonPublicClientOptions;
11
+ /**
12
+ * Common options that can be used on public `generateClient()` interfaces.
13
+ */
14
+ export type CommonPublicClientOptions = {
15
+ authMode?: GraphQLAuthMode;
16
+ authToken?: string;
17
+ };
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,10 +1,13 @@
1
1
  import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
2
+ import { ModelTypes } from '@aws-amplify/data-schema-types';
2
3
  import { Source, DocumentNode, GraphQLError } from 'graphql';
3
4
  export { OperationTypeNode } from 'graphql';
4
5
  import { Observable } from 'rxjs';
5
6
  import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
6
7
  import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
7
8
  export { CONTROL_MSG, ConnectionState } from './PubSub';
9
+ export { SelectionSet } from '@aws-amplify/data-schema-types';
10
+ export { CommonPublicClientOptions } from '../internals/types';
8
11
  /**
9
12
  * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
10
13
  */
@@ -280,17 +283,34 @@ type ExcludeNeverFields<O> = {
280
283
  [K in FilteredKeys<O>]: O[K];
281
284
  };
282
285
  export declare const __amplify: unique symbol;
286
+ export declare const __authMode: unique symbol;
287
+ export declare const __authToken: unique symbol;
283
288
  export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
284
289
  [__amplify]: AmplifyClassV6;
290
+ [__authMode]?: GraphQLAuthMode;
291
+ [__authToken]?: string;
285
292
  graphql: GraphQLMethod;
286
293
  cancel: (promise: Promise<any>, message?: string) => boolean;
287
294
  isCancelError: (error: any) => boolean;
295
+ models: ModelTypes<T>;
288
296
  }>;
289
- export type V6ClientSSR<T extends Record<any, any> = never> = ExcludeNeverFields<{
297
+ export type V6ClientSSRRequest<T extends Record<any, any> = never> = ExcludeNeverFields<{
290
298
  [__amplify]: AmplifyClassV6;
299
+ [__authMode]?: GraphQLAuthMode;
300
+ [__authToken]?: string;
291
301
  graphql: GraphQLMethodSSR;
292
302
  cancel: (promise: Promise<any>, message?: string) => boolean;
293
303
  isCancelError: (error: any) => boolean;
304
+ models: ModelTypes<T, 'REQUEST'>;
305
+ }>;
306
+ export type V6ClientSSRCookies<T extends Record<any, any> = never> = ExcludeNeverFields<{
307
+ [__amplify]: AmplifyClassV6;
308
+ [__authMode]?: GraphQLAuthMode;
309
+ [__authToken]?: string;
310
+ graphql: GraphQLMethod;
311
+ cancel: (promise: Promise<any>, message?: string) => boolean;
312
+ isCancelError: (error: any) => boolean;
313
+ models: ModelTypes<T, 'COOKIES'>;
294
314
  }>;
295
315
  export type GraphQLMethod = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
296
316
  [key: string]: string;
@@ -304,6 +324,6 @@ export type GraphQLMethodSSR = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING exten
304
324
  * The knobs available for configuring `server/generateClient` internally.
305
325
  */
306
326
  export type ServerClientGenerationParams = {
307
- amplify: null | ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>);
327
+ amplify: null | ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
308
328
  config: ResourcesConfig;
309
329
  };
@@ -9,6 +9,8 @@ var GraphQLAuthError;
9
9
  GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
10
10
  })(GraphQLAuthError || (GraphQLAuthError = {}));
11
11
  const __amplify = Symbol('amplify');
12
+ const __authMode = Symbol('authMode');
13
+ const __authToken = Symbol('authToken');
12
14
 
13
- export { GraphQLAuthError, __amplify };
15
+ export { GraphQLAuthError, __amplify, __authMode, __authToken };
14
16
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/types/index.ts"],"sourcesContent":["export { CONTROL_MSG, ConnectionState } from './PubSub';\nexport var GraphQLAuthError;\n(function (GraphQLAuthError) {\n GraphQLAuthError[\"NO_API_KEY\"] = \"No api-key configured\";\n GraphQLAuthError[\"NO_CURRENT_USER\"] = \"No current user\";\n GraphQLAuthError[\"NO_CREDENTIALS\"] = \"No credentials\";\n GraphQLAuthError[\"NO_FEDERATED_JWT\"] = \"No federated jwt\";\n GraphQLAuthError[\"NO_AUTH_TOKEN\"] = \"No auth token specified\";\n})(GraphQLAuthError || (GraphQLAuthError = {}));\nexport const __amplify = Symbol('amplify');\n"],"names":[],"mappings":";;AACU,IAAC,iBAAiB;AAC5B,CAAC,UAAU,gBAAgB,EAAE;AAC7B,IAAI,gBAAgB,CAAC,YAAY,CAAC,GAAG,uBAAuB,CAAC;AAC7D,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAAC;AAC5D,IAAI,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;AAC1D,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AAC9D,IAAI,gBAAgB,CAAC,eAAe,CAAC,GAAG,yBAAyB,CAAC;AAClE,CAAC,EAAE,gBAAgB,KAAK,gBAAgB,GAAG,EAAE,CAAC,CAAC,CAAC;AACpC,MAAC,SAAS,GAAG,MAAM,CAAC,SAAS;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/types/index.ts"],"sourcesContent":["export { CONTROL_MSG, ConnectionState } from './PubSub';\nexport var GraphQLAuthError;\n(function (GraphQLAuthError) {\n GraphQLAuthError[\"NO_API_KEY\"] = \"No api-key configured\";\n GraphQLAuthError[\"NO_CURRENT_USER\"] = \"No current user\";\n GraphQLAuthError[\"NO_CREDENTIALS\"] = \"No credentials\";\n GraphQLAuthError[\"NO_FEDERATED_JWT\"] = \"No federated jwt\";\n GraphQLAuthError[\"NO_AUTH_TOKEN\"] = \"No auth token specified\";\n})(GraphQLAuthError || (GraphQLAuthError = {}));\nexport const __amplify = Symbol('amplify');\nexport const __authMode = Symbol('authMode');\nexport const __authToken = Symbol('authToken');\n"],"names":[],"mappings":";;AACU,IAAC,iBAAiB;AAC5B,CAAC,UAAU,gBAAgB,EAAE;AAC7B,IAAI,gBAAgB,CAAC,YAAY,CAAC,GAAG,uBAAuB,CAAC;AAC7D,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAAC;AAC5D,IAAI,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;AAC1D,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AAC9D,IAAI,gBAAgB,CAAC,eAAe,CAAC,GAAG,yBAAyB,CAAC;AAClE,CAAC,EAAE,gBAAgB,KAAK,gBAAgB,GAAG,EAAE,CAAC,CAAC,CAAC;AACpC,MAAC,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE;AAC/B,MAAC,UAAU,GAAG,MAAM,CAAC,UAAU,EAAE;AACjC,MAAC,WAAW,GAAG,MAAM,CAAC,WAAW;;;;"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Iterates through a collection to find a matching item and returns the index.
3
+ *
4
+ * @param needle The item to search for
5
+ * @param haystack The collection to search
6
+ * @param keyFields The fields used to indicate a match
7
+ * @returns Index of `needle` in `haystack`, otherwise -1 if not found.
8
+ */
9
+ export declare function findIndexByFields<T>(needle: T, haystack: T[], keyFields: Array<keyof T>): number;
@@ -0,0 +1,22 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Iterates through a collection to find a matching item and returns the index.
5
+ *
6
+ * @param needle The item to search for
7
+ * @param haystack The collection to search
8
+ * @param keyFields The fields used to indicate a match
9
+ * @returns Index of `needle` in `haystack`, otherwise -1 if not found.
10
+ */
11
+ function findIndexByFields(needle, haystack, keyFields) {
12
+ const searchObject = Object.fromEntries(keyFields.map(fieldName => [fieldName, needle[fieldName]]));
13
+ for (let i = 0; i < haystack.length; i++) {
14
+ if (Object.keys(searchObject).every(k => searchObject[k] === haystack[i][k])) {
15
+ return i;
16
+ }
17
+ }
18
+ return -1;
19
+ }
20
+
21
+ export { findIndexByFields };
22
+ //# sourceMappingURL=findIndexByFields.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findIndexByFields.mjs","sources":["../../../src/utils/findIndexByFields.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Iterates through a collection to find a matching item and returns the index.\n *\n * @param needle The item to search for\n * @param haystack The collection to search\n * @param keyFields The fields used to indicate a match\n * @returns Index of `needle` in `haystack`, otherwise -1 if not found.\n */\nexport function findIndexByFields(needle, haystack, keyFields) {\n const searchObject = Object.fromEntries(keyFields.map(fieldName => [fieldName, needle[fieldName]]));\n for (let i = 0; i < haystack.length; i++) {\n if (Object.keys(searchObject).every(k => searchObject[k] === haystack[i][k])) {\n return i;\n }\n }\n return -1;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE;AAC/D,IAAI,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACxG,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC9C,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;AACtF,YAAY,OAAO,CAAC,CAAC;AACrB,SAAS;AACT,KAAK;AACL,IAAI,OAAO,CAAC,CAAC,CAAC;AACd;;;;"}
@@ -1,2 +1,4 @@
1
1
  export { resolveConfig } from './resolveConfig';
2
2
  export { resolveLibraryOptions } from './resolveLibraryOptions';
3
+ export { resolvePKFields } from './resolvePKFields';
4
+ export { findIndexByFields } from './findIndexByFields';
@@ -1,3 +1,5 @@
1
1
  export { resolveConfig } from './resolveConfig.mjs';
2
2
  export { resolveLibraryOptions } from './resolveLibraryOptions.mjs';
3
+ export { resolvePKFields } from './resolvePKFields.mjs';
4
+ export { findIndexByFields } from './findIndexByFields.mjs';
3
5
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,12 @@
1
+ import { ResourcesConfig } from '@aws-amplify/core';
2
+ type GraphQLConfig = Exclude<ResourcesConfig['API'], undefined>['GraphQL'];
3
+ type ModelIntrospectionSchema = Exclude<Exclude<GraphQLConfig, undefined>['modelIntrospection'], undefined>;
4
+ type Model = ModelIntrospectionSchema['models'][string];
5
+ /**
6
+ * Given an introspection schema model, returns all owner fields.
7
+ *
8
+ * @param model Model from an introspection schema
9
+ * @returns List of owner field names
10
+ */
11
+ export declare function resolveOwnerFields(model: Model): string[];
12
+ export {};
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Given an introspection schema model, returns all owner fields.
3
+ *
4
+ * @param model Model from an introspection schema
5
+ * @returns List of owner field names
6
+ */
7
+ function resolveOwnerFields(model) {
8
+ const ownerFields = new Set();
9
+ for (const attr of model.attributes || []) {
10
+ if (isAuthAttribute(attr)) {
11
+ for (const rule of attr.properties.rules) {
12
+ if (rule.allow === 'owner') {
13
+ ownerFields.add(rule.ownerField || 'owner');
14
+ }
15
+ }
16
+ }
17
+ }
18
+ return Array.from(ownerFields);
19
+ }
20
+ /**
21
+ * Type guard that identifies an auth attribute with an attached rules list that
22
+ * specifies an `allow` attribute at a minimum.
23
+ *
24
+ * @param attribute Any object. Ideally a model introspection schema model attribute
25
+ * @returns True if given object is an auth attribute
26
+ */
27
+ function isAuthAttribute(attribute) {
28
+ if (attribute?.type === 'auth') {
29
+ if (typeof attribute?.properties === 'object') {
30
+ if (Array.isArray(attribute?.properties?.rules)) {
31
+ return (attribute?.properties?.rules).every(rule => !!rule.allow);
32
+ }
33
+ }
34
+ }
35
+ return false;
36
+ }
37
+
38
+ export { resolveOwnerFields };
39
+ //# sourceMappingURL=resolveOwnerFields.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveOwnerFields.mjs","sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nexport function resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,MAAM,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;AAClC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;AAC/C,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;AACnC,YAAY,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACtD,gBAAgB,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC5C,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC;AAChE,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,SAAS,EAAE;AACpC,IAAI,IAAI,SAAS,EAAE,IAAI,KAAK,MAAM,EAAE;AACpC,QAAQ,IAAI,OAAO,SAAS,EAAE,UAAU,KAAK,QAAQ,EAAE;AACvD,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE;AAC7D,gBAAgB,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClF,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
@@ -0,0 +1,13 @@
1
+ import { ResourcesConfig } from '@aws-amplify/core';
2
+ type GraphQLConfig = Exclude<ResourcesConfig['API'], undefined>['GraphQL'];
3
+ type ModelIntrospectionSchema = Exclude<Exclude<GraphQLConfig, undefined>['modelIntrospection'], undefined>;
4
+ type SchemaModel = ModelIntrospectionSchema['models'][string];
5
+ /**
6
+ * Given a SchemaModel from a ModelIntrospectionSchema, returns the primary key
7
+ * as an array of field names.
8
+ *
9
+ * @param model The model object
10
+ * @returns Array of field names
11
+ */
12
+ export declare function resolvePKFields(model: SchemaModel): string[];
13
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Given a SchemaModel from a ModelIntrospectionSchema, returns the primary key
3
+ * as an array of field names.
4
+ *
5
+ * @param model The model object
6
+ * @returns Array of field names
7
+ */
8
+ function resolvePKFields(model) {
9
+ const { primaryKeyFieldName, sortKeyFieldNames } = model.primaryKeyInfo;
10
+ return [primaryKeyFieldName, ...sortKeyFieldNames];
11
+ }
12
+
13
+ export { resolvePKFields };
14
+ //# sourceMappingURL=resolvePKFields.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolvePKFields.mjs","sources":["../../../src/utils/resolvePKFields.ts"],"sourcesContent":["/**\n * Given a SchemaModel from a ModelIntrospectionSchema, returns the primary key\n * as an array of field names.\n *\n * @param model The model object\n * @returns Array of field names\n */\nexport function resolvePKFields(model) {\n const { primaryKeyFieldName, sortKeyFieldNames } = model.primaryKeyInfo;\n return [primaryKeyFieldName, ...sortKeyFieldNames];\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,KAAK,EAAE;AACvC,IAAI,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC;AAC5E,IAAI,OAAO,CAAC,mBAAmB,EAAE,GAAG,iBAAiB,CAAC,CAAC;AACvD;;;;"}
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@aws-amplify/api-graphql/internals/server",
3
+ "types": "../../dist/esm/internals/server/index.d.ts",
4
+ "main": "../../dist/cjs/internals/server/index.js",
5
+ "module": "../../dist/esm/internals/server/index.mjs",
6
+ "react-native": "../../src/internals/server/index.ts",
7
+ "sideEffects": false
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "4.0.1",
3
+ "version": "4.0.2-unstable.b778a9e.0+b778a9e",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -41,6 +41,12 @@
41
41
  "require": "./dist/cjs/internals/index.js",
42
42
  "react-native": "./src/internals/index.ts"
43
43
  },
44
+ "./internals/server": {
45
+ "types": "./dist/esm/internals/server/index.d.ts",
46
+ "import": "./dist/esm/internals/server/index.mjs",
47
+ "require": "./dist/cjs/internals/server/index.js",
48
+ "react-native": "./src/internals/server/index.ts"
49
+ },
44
50
  "./package.json": "./package.json"
45
51
  },
46
52
  "typesVersions": {
@@ -60,13 +66,10 @@
60
66
  "url": "https://github.com/aws/aws-amplify/issues"
61
67
  },
62
68
  "homepage": "https://aws-amplify.github.io/",
63
- "peerDependencies": {
64
- "@aws-amplify/core": "^6.0.0"
65
- },
66
69
  "devDependencies": {
67
- "@aws-amplify/core": "6.0.1",
68
70
  "@rollup/plugin-typescript": "11.1.5",
69
- "rollup": "3.29.4"
71
+ "rollup": "3.29.4",
72
+ "typescript": "5.1.6"
70
73
  },
71
74
  "files": [
72
75
  "dist/cjs",
@@ -75,11 +78,14 @@
75
78
  "internals"
76
79
  ],
77
80
  "dependencies": {
78
- "@aws-amplify/api-rest": "4.0.1",
81
+ "@aws-amplify/api-rest": "4.0.2-unstable.b778a9e.0+b778a9e",
82
+ "@aws-amplify/core": "6.0.2-unstable.b778a9e.0+b778a9e",
83
+ "@aws-amplify/data-schema-types": "^0.4.2",
79
84
  "@aws-sdk/types": "3.387.0",
80
85
  "graphql": "15.8.0",
81
86
  "rxjs": "^7.8.1",
82
- "tslib": "^2.5.0"
87
+ "tslib": "^2.5.0",
88
+ "uuid": "^9.0.0"
83
89
  },
84
90
  "size-limit": [
85
91
  {
@@ -144,5 +150,5 @@
144
150
  "<rootDir>/__tests__"
145
151
  ]
146
152
  },
147
- "gitHead": "f1408db3f570c4a18ada40cecbe7e68a0b31f1fe"
153
+ "gitHead": "b778a9e3b05c6f0f52fcfaab79729f4d7d439444"
148
154
  }