@aws-amplify/data-schema 1.3.4 → 1.3.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/data-schema",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,6 +4,7 @@ import {
4
4
  type InternalField,
5
5
  string,
6
6
  type BaseModelField,
7
+ ModelFieldType,
7
8
  } from './ModelField';
8
9
  import { type InternalRelationalField } from './ModelRelationalField';
9
10
  import type { InternalModel } from './ModelType';
@@ -484,6 +485,34 @@ function escapeGraphQlString(str: string) {
484
485
  return JSON.stringify(str);
485
486
  }
486
487
 
488
+ /**
489
+ * AWS AppSync scalars that are stored as strings in the data source
490
+ */
491
+ const stringFieldTypes = {
492
+ ID: true,
493
+ String: true,
494
+ AWSDate: true,
495
+ AWSTime: true,
496
+ AWSDateTime: true,
497
+ AWSEmail: true,
498
+ AWSPhone: true,
499
+ AWSURL: true,
500
+ AWSIPAddress: true,
501
+ };
502
+
503
+ /**
504
+ * Normalize string-compatible field types for comparison
505
+ */
506
+ const normalizeStringFieldTypes = (
507
+ fieldType: ModelFieldType,
508
+ ): ModelFieldType => {
509
+ if (fieldType in stringFieldTypes) {
510
+ return ModelFieldType.String;
511
+ }
512
+
513
+ return fieldType;
514
+ };
515
+
487
516
  /**
488
517
  * Tests whether two ModelField definitions are in conflict.
489
518
  *
@@ -496,15 +525,24 @@ function escapeGraphQlString(str: string) {
496
525
  * @returns
497
526
  */
498
527
  function areConflicting(left: BaseModelField, right: BaseModelField): boolean {
499
- // These are the only props we care about for this comparison, because the others
528
+ const leftData = (left as InternalField).data;
529
+ const rightData = (right as InternalField).data;
530
+
531
+ // `array` and `fieldType` are the only props we care about for this comparison, because the others
500
532
  // (required, arrayRequired, etc) are not specified on auth or FK directives.
501
- const relevantProps = ['array', 'fieldType'] as const;
502
- for (const prop of relevantProps) {
503
- if (
504
- (left as InternalField).data[prop] !== (right as InternalField).data[prop]
505
- ) {
506
- return true;
507
- }
533
+ if (leftData.array !== rightData.array) {
534
+ return true;
535
+ }
536
+
537
+ // Convert "string-compatible" field types to `String` for the sake of this comparison
538
+ //
539
+ // E.g. if a customer has an explicit a.id() field that they're referencing in an allow.ownerDefinedIn rule
540
+ // we treat ID and String as equivalent/non-conflicting
541
+ if (
542
+ normalizeStringFieldTypes(leftData.fieldType) !==
543
+ normalizeStringFieldTypes(rightData.fieldType)
544
+ ) {
545
+ return true;
508
546
  }
509
547
 
510
548
  return false;
@@ -46,7 +46,7 @@ const skGraphQlFieldTypeMap = {
46
46
  AWSDate: 'String',
47
47
  AWSTime: 'String',
48
48
  AWSDateTime: 'String',
49
- AWSTimestamp: 'String',
49
+ AWSTimestamp: 'Int',
50
50
  AWSEmail: 'String',
51
51
  AWSPhone: 'String',
52
52
  AWSURL: 'String',