diff --git a/packages/datastore/src/authModeStrategies/defaultAuthStrategy.ts b/packages/datastore/src/authModeStrategies/defaultAuthStrategy.ts index 983f63dd848..4cdda180f6c 100644 --- a/packages/datastore/src/authModeStrategies/defaultAuthStrategy.ts +++ b/packages/datastore/src/authModeStrategies/defaultAuthStrategy.ts @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { AuthModeStrategy } from '~/types'; +import { AuthModeStrategy } from '~/src/types'; // Default behavior is to use the primary auth mode for an API, // so we are returning an empty array so that DataStore will default diff --git a/packages/datastore/src/authModeStrategies/multiAuthStrategy.ts b/packages/datastore/src/authModeStrategies/multiAuthStrategy.ts index 911911ab915..c5597f492a6 100644 --- a/packages/datastore/src/authModeStrategies/multiAuthStrategy.ts +++ b/packages/datastore/src/authModeStrategies/multiAuthStrategy.ts @@ -7,7 +7,7 @@ import { ModelAttributeAuthAllow, ModelAttributeAuthProperty, ModelAttributeAuthProvider, -} from '~/types'; +} from '~/src/types'; import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils'; function getProviderFromRule( diff --git a/packages/datastore/src/datastore/datastore.ts b/packages/datastore/src/datastore/datastore.ts index 72538b3a426..21d185b1b90 100644 --- a/packages/datastore/src/datastore/datastore.ts +++ b/packages/datastore/src/datastore/datastore.ts @@ -16,17 +16,20 @@ import { isBrowser, } from '@aws-amplify/core/internals/utils'; import { Observable, SubscriptionLike, filter } from 'rxjs'; -import { defaultAuthStrategy, multiAuthStrategy } from '~/authModeStrategies'; +import { + defaultAuthStrategy, + multiAuthStrategy, +} from '~/src/authModeStrategies'; import { ModelPredicateCreator, ModelSortPredicateCreator, PredicateAll, isPredicatesAll, -} from '~/predicates'; -import { Adapter } from '~/storage/adapter'; -import { ExclusiveStorage as Storage } from '~/storage/storage'; -import { ModelRelationship } from '~/storage/relationship'; -import { ControlMessage, SyncEngine } from '~/sync'; +} from '~/src/predicates'; +import { Adapter } from '~/src/storage/adapter'; +import { ExclusiveStorage as Storage } from '~/src/storage/storage'; +import { ModelRelationship } from '~/src/storage/relationship'; +import { ControlMessage, SyncEngine } from '~/src/sync'; import { AmplifyContext, AuthModeStrategy, @@ -69,8 +72,8 @@ import { isModelFieldType, isNonModelFieldType, isSchemaModelWithAttributes, -} from '~/types'; -import type { __modelMeta__ } from '~/types'; +} from '~/src/types'; +import type { __modelMeta__ } from '~/src/types'; import { DATASTORE, DeferredCallbackResolver, @@ -92,15 +95,15 @@ import { monotonicUlidFactory, registerNonModelClass, sortCompareFunction, -} from '~/util'; +} from '~/src/util'; import { GroupCondition, internals, predicateFor, recursivePredicateFor, -} from '~/predicates/next'; -import { getIdentifierValue } from '~/sync/utils'; -import DataStoreConnectivity from '~/sync/datastoreConnectivity'; +} from '~/src/predicates/next'; +import { getIdentifierValue } from '~/src/sync/utils'; +import DataStoreConnectivity from '~/src/sync/datastoreConnectivity'; setAutoFreeze(true); enablePatches(); @@ -651,6 +654,8 @@ const validateModelFields = ); } } + } else if (!isRequired && v === undefined) { + // no-op } else if (typeof v !== jsType && v !== null) { throw new Error( `Field ${name} should be of type ${jsType}, ${typeof v} received. ${v}`, diff --git a/packages/datastore/src/predicates/index.ts b/packages/datastore/src/predicates/index.ts index 8657dc94e14..dfed17a9f81 100644 --- a/packages/datastore/src/predicates/index.ts +++ b/packages/datastore/src/predicates/index.ts @@ -6,8 +6,11 @@ import { PredicatesGroup, ProducerModelPredicate, SchemaModel, -} from '~/types'; -import { extractPrimaryKeyFieldNames, extractPrimaryKeyValues } from '~/util'; +} from '~/src/types'; +import { + extractPrimaryKeyFieldNames, + extractPrimaryKeyValues, +} from '~/src/util'; export { ModelSortPredicateCreator } from './sort'; diff --git a/packages/datastore/src/predicates/next.ts b/packages/datastore/src/predicates/next.ts index 22dd8a706f1..c08eed7a42c 100644 --- a/packages/datastore/src/predicates/next.ts +++ b/packages/datastore/src/predicates/next.ts @@ -11,10 +11,10 @@ import { RecursiveModelPredicateAggregateExtender, RecursiveModelPredicateExtender, ModelPredicate as StoragePredicate, -} from '~/types'; -import { ExclusiveStorage as StorageAdapter } from '~/storage/storage'; -import { ModelRelationship } from '~/storage/relationship'; -import { asyncEvery, asyncSome } from '~/util'; +} from '~/src/types'; +import { ExclusiveStorage as StorageAdapter } from '~/src/storage/storage'; +import { ModelRelationship } from '~/src/storage/relationship'; +import { asyncEvery, asyncSome } from '~/src/util'; import { ModelPredicateCreator as FlatModelPredicateCreator, diff --git a/packages/datastore/src/predicates/sort.ts b/packages/datastore/src/predicates/sort.ts index 2d3d7c1afd6..ff8624e1672 100644 --- a/packages/datastore/src/predicates/sort.ts +++ b/packages/datastore/src/predicates/sort.ts @@ -7,7 +7,7 @@ import { SortDirection, SortPredicate, SortPredicatesGroup, -} from '~/types'; +} from '~/src/types'; export class ModelSortPredicateCreator { private static sortPredicateGroupsMap = new WeakMap< diff --git a/packages/datastore/src/storage/adapter/AsyncStorageAdapter.ts b/packages/datastore/src/storage/adapter/AsyncStorageAdapter.ts index dcb8184c1da..5ea223837cc 100644 --- a/packages/datastore/src/storage/adapter/AsyncStorageAdapter.ts +++ b/packages/datastore/src/storage/adapter/AsyncStorageAdapter.ts @@ -9,7 +9,7 @@ import { PersistentModelConstructor, PredicatesGroup, QueryOne, -} from '~/types'; +} from '~/src/types'; import { DEFAULT_PRIMARY_KEY_VALUE_SEPARATOR, getIndexKeys, @@ -18,7 +18,7 @@ import { keysEqual, traverseModel, validatePredicate, -} from '~/util'; +} from '~/src/util'; import AsyncStorageDatabase from './AsyncStorageDatabase'; import { StorageAdapterBase } from './StorageAdapterBase'; diff --git a/packages/datastore/src/storage/adapter/AsyncStorageDatabase.ts b/packages/datastore/src/storage/adapter/AsyncStorageDatabase.ts index d324abafa58..631e9ab3862 100644 --- a/packages/datastore/src/storage/adapter/AsyncStorageDatabase.ts +++ b/packages/datastore/src/storage/adapter/AsyncStorageDatabase.ts @@ -7,12 +7,12 @@ import { PaginationInput, PersistentModel, QueryOne, -} from '~/types'; +} from '~/src/types'; import { DEFAULT_PRIMARY_KEY_VALUE_SEPARATOR, indexNameFromKeys, monotonicUlidFactory, -} from '~/util'; +} from '~/src/util'; import { createInMemoryStore } from './InMemoryStore'; diff --git a/packages/datastore/src/storage/adapter/IndexedDBAdapter.ts b/packages/datastore/src/storage/adapter/IndexedDBAdapter.ts index 655d4154d53..e67db509c33 100644 --- a/packages/datastore/src/storage/adapter/IndexedDBAdapter.ts +++ b/packages/datastore/src/storage/adapter/IndexedDBAdapter.ts @@ -13,7 +13,7 @@ import { QueryOne, isPredicateGroup, isPredicateObj, -} from '~/types'; +} from '~/src/types'; import { getStorename, inMemoryPagination, @@ -22,7 +22,7 @@ import { keysEqual, traverseModel, validatePredicate, -} from '~/util'; +} from '~/src/util'; import { ConsoleLogger } from '@aws-amplify/core'; import { StorageAdapterBase } from './StorageAdapterBase'; diff --git a/packages/datastore/src/storage/adapter/StorageAdapterBase.ts b/packages/datastore/src/storage/adapter/StorageAdapterBase.ts index 6738bf599a1..7af0c62a7e3 100644 --- a/packages/datastore/src/storage/adapter/StorageAdapterBase.ts +++ b/packages/datastore/src/storage/adapter/StorageAdapterBase.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ModelInstanceCreator } from '~/datastore/datastore'; -import { ModelPredicateCreator } from '~/predicates'; +import { ModelInstanceCreator } from '~/src/datastore/datastore'; +import { ModelPredicateCreator } from '~/src/predicates'; import { InternalSchema, ModelInstanceMetadata, @@ -15,7 +15,7 @@ import { PredicatesGroup, QueryOne, isPredicateObj, -} from '~/types'; +} from '~/src/types'; import { NAMESPACES, extractPrimaryKeyFieldNames, @@ -25,8 +25,8 @@ import { isModelConstructor, traverseModel, validatePredicate, -} from '~/util'; -import { ModelRelationship } from '~/storage/relationship'; +} from '~/src/util'; +import { ModelRelationship } from '~/src/storage/relationship'; import { ConsoleLogger } from '@aws-amplify/core'; import { Adapter } from './index'; diff --git a/packages/datastore/src/storage/adapter/getDefaultAdapter/index.native.ts b/packages/datastore/src/storage/adapter/getDefaultAdapter/index.native.ts index ba93311df28..76c4ab3fb8c 100644 --- a/packages/datastore/src/storage/adapter/getDefaultAdapter/index.native.ts +++ b/packages/datastore/src/storage/adapter/getDefaultAdapter/index.native.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { Adapter } from '..'; -import AsyncStorageAdapter from '~/storage/adapter/AsyncStorageAdapter'; +import AsyncStorageAdapter from '~/src/storage/adapter/AsyncStorageAdapter'; const getDefaultAdapter: () => Adapter = () => { return AsyncStorageAdapter; diff --git a/packages/datastore/src/storage/adapter/getDefaultAdapter/index.ts b/packages/datastore/src/storage/adapter/getDefaultAdapter/index.ts index a4cc000eed6..a73373e61c9 100644 --- a/packages/datastore/src/storage/adapter/getDefaultAdapter/index.ts +++ b/packages/datastore/src/storage/adapter/getDefaultAdapter/index.ts @@ -1,8 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { Adapter } from '..'; -import IndexedDBAdapter from '~/storage/adapter/IndexedDBAdapter'; -import AsyncStorageAdapter from '~/storage/adapter/AsyncStorageAdapter'; +import IndexedDBAdapter from '~/src/storage/adapter/IndexedDBAdapter'; +import AsyncStorageAdapter from '~/src/storage/adapter/AsyncStorageAdapter'; import { isBrowser, isWebWorker } from '@aws-amplify/core/internals/utils'; const getDefaultAdapter: () => Adapter = () => { diff --git a/packages/datastore/src/storage/adapter/index.ts b/packages/datastore/src/storage/adapter/index.ts index ae96ee4bf03..e6f75f47bfa 100644 --- a/packages/datastore/src/storage/adapter/index.ts +++ b/packages/datastore/src/storage/adapter/index.ts @@ -9,29 +9,29 @@ import { PersistentModelConstructor, QueryOne, SystemComponent, -} from '~/types'; +} from '~/src/types'; export interface Adapter extends SystemComponent { clear(): Promise; save( model: T, - condition?: ModelPredicate + condition?: ModelPredicate, ): Promise<[T, OpType.INSERT | OpType.UPDATE][]>; delete( modelOrModelConstructor: T | PersistentModelConstructor, - condition?: ModelPredicate + condition?: ModelPredicate, ): Promise<[T[], T[]]>; query( modelConstructor: PersistentModelConstructor, predicate?: ModelPredicate, - pagination?: PaginationInput + pagination?: PaginationInput, ): Promise; queryOne( modelConstructor: PersistentModelConstructor, - firstOrLast: QueryOne + firstOrLast: QueryOne, ): Promise; batchSave( modelConstructor: PersistentModelConstructor, - items: ModelInstanceMetadata[] + items: ModelInstanceMetadata[], ): Promise<[T, OpType][]>; } diff --git a/packages/datastore/src/storage/relationship.ts b/packages/datastore/src/storage/relationship.ts index 5878df93003..eee7c0e882a 100644 --- a/packages/datastore/src/storage/relationship.ts +++ b/packages/datastore/src/storage/relationship.ts @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ModelFieldType, ModelMeta, isFieldAssociation } from '~/types'; +import { ModelFieldType, ModelMeta, isFieldAssociation } from '~/src/types'; /** * Defines a relationship from a LOCAL model.field to a REMOTE model.field and helps diff --git a/packages/datastore/src/storage/storage.ts b/packages/datastore/src/storage/storage.ts index 00aab628d69..f5801c02056 100644 --- a/packages/datastore/src/storage/storage.ts +++ b/packages/datastore/src/storage/storage.ts @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { Observable, Subject, filter, map } from 'rxjs'; import { Patch } from 'immer'; -import { ModelInstanceCreator } from '~/datastore/datastore'; -import { ModelPredicateCreator } from '~/predicates'; +import { ModelInstanceCreator } from '~/src/datastore/datastore'; +import { ModelPredicateCreator } from '~/src/predicates'; import { InternalSchema, InternalSubscriptionMessage, @@ -19,15 +19,15 @@ import { SchemaNamespace, SubscriptionMessage, isTargetNameAssociation, -} from '~/types'; +} from '~/src/types'; import { NAMESPACES, STORAGE, isModelConstructor, validatePredicate, valuesEqual, -} from '~/util'; -import { getIdentifierValue } from '~/sync/utils'; +} from '~/src/util'; +import { getIdentifierValue } from '~/src/sync/utils'; import { Mutex } from '@aws-amplify/core/internals/utils'; import { ConsoleLogger } from '@aws-amplify/core'; diff --git a/packages/datastore/src/sync/index.ts b/packages/datastore/src/sync/index.ts index ee87edc0e90..cc5d53d327c 100644 --- a/packages/datastore/src/sync/index.ts +++ b/packages/datastore/src/sync/index.ts @@ -3,9 +3,9 @@ import { BackgroundProcessManager } from '@aws-amplify/core/internals/utils'; import { ConsoleLogger, Hub } from '@aws-amplify/core'; import { Observable, SubscriptionLike, filter, of } from 'rxjs'; -import { ModelInstanceCreator } from '~/datastore/datastore'; -import { ModelPredicateCreator } from '~/predicates'; -import { ExclusiveStorage as Storage } from '~/storage/storage'; +import { ModelInstanceCreator } from '~/src/datastore/datastore'; +import { ModelPredicateCreator } from '~/src/predicates'; +import { ExclusiveStorage as Storage } from '~/src/storage/storage'; import { AmplifyContext, AuthModeStrategy, @@ -26,9 +26,9 @@ import { SchemaModel, SchemaNamespace, TypeConstructorMap, -} from '~/types'; -import type { __modelMeta__ } from '~/types'; -import { SYNC, USER, getNow } from '~/util'; +} from '~/src/types'; +import type { __modelMeta__ } from '~/src/types'; +import { SYNC, USER, getNow } from '~/src/util'; import { ConnectionState, CONNECTION_STATE_CHANGE as PUBSUB_CONNECTION_STATE_CHANGE, diff --git a/packages/datastore/src/sync/merger.ts b/packages/datastore/src/sync/merger.ts index 8a3e37f5dfc..633e6283fc2 100644 --- a/packages/datastore/src/sync/merger.ts +++ b/packages/datastore/src/sync/merger.ts @@ -1,12 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { Storage } from '~/storage/storage'; +import { Storage } from '~/src/storage/storage'; import { ModelInstanceMetadata, OpType, PersistentModelConstructor, SchemaModel, -} from '~/types'; +} from '~/src/types'; import { MutationEventOutbox } from './outbox'; import { getIdentifierValue } from './utils'; diff --git a/packages/datastore/src/sync/outbox.ts b/packages/datastore/src/sync/outbox.ts index 34ab001b73d..c0e51571913 100644 --- a/packages/datastore/src/sync/outbox.ts +++ b/packages/datastore/src/sync/outbox.ts @@ -1,20 +1,20 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ModelPredicateCreator } from '~/predicates'; +import { ModelPredicateCreator } from '~/src/predicates'; import { ExclusiveStorage as Storage, Storage as StorageClass, StorageFacade, -} from '~/storage/storage'; -import { ModelInstanceCreator } from '~/datastore/datastore'; +} from '~/src/storage/storage'; +import { ModelInstanceCreator } from '~/src/datastore/datastore'; import { InternalSchema, PersistentModel, PersistentModelConstructor, QueryOne, SchemaModel, -} from '~/types'; -import { SYNC, USER, valuesEqual } from '~/util'; +} from '~/src/types'; +import { SYNC, USER, valuesEqual } from '~/src/util'; import { TransformerMutationType, getIdentifierValue } from './utils'; diff --git a/packages/datastore/src/sync/processors/errorMaps.ts b/packages/datastore/src/sync/processors/errorMaps.ts index 73592dc6166..aee562f5791 100644 --- a/packages/datastore/src/sync/processors/errorMaps.ts +++ b/packages/datastore/src/sync/processors/errorMaps.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ErrorType } from '~/types'; -import { resolveServiceErrorStatusCode } from '~/sync/utils'; +import { ErrorType } from '~/src/types'; +import { resolveServiceErrorStatusCode } from '~/src/sync/utils'; export type ErrorMap = Partial<{ [key in ErrorType]: (error: Error) => boolean; diff --git a/packages/datastore/src/sync/processors/mutation.ts b/packages/datastore/src/sync/processors/mutation.ts index 8e36a431c8f..d65cdf16c6c 100644 --- a/packages/datastore/src/sync/processors/mutation.ts +++ b/packages/datastore/src/sync/processors/mutation.ts @@ -13,9 +13,9 @@ import { retry, } from '@aws-amplify/core/internals/utils'; import { Observable, Observer } from 'rxjs'; -import { MutationEvent } from '~/sync'; -import { ModelInstanceCreator } from '~/datastore/datastore'; -import { ExclusiveStorage as Storage } from '~/storage/storage'; +import { MutationEvent } from '~/src/sync'; +import { ModelInstanceCreator } from '~/src/datastore/datastore'; +import { ExclusiveStorage as Storage } from '~/src/storage/storage'; import { AmplifyContext, AuthModeStrategy, @@ -33,16 +33,16 @@ import { TypeConstructorMap, isModelFieldType, isTargetNameAssociation, -} from '~/types'; -import { ID, USER, extractTargetNamesFromSrc } from '~/util'; -import { MutationEventOutbox } from '~/sync/outbox'; +} from '~/src/types'; +import { ID, USER, extractTargetNamesFromSrc } from '~/src/util'; +import { MutationEventOutbox } from '~/src/sync/outbox'; import { TransformerMutationType, buildGraphQLOperation, createMutationInstanceFromModelOperation, getModelAuthModes, getTokenForCustomAuth, -} from '~/sync/utils'; +} from '~/src/sync/utils'; import { ConsoleLogger } from '@aws-amplify/core'; import { getMutationErrorType } from './errorMaps'; diff --git a/packages/datastore/src/sync/processors/subscription.ts b/packages/datastore/src/sync/processors/subscription.ts index 4af28936b7e..4be2f014108 100644 --- a/packages/datastore/src/sync/processors/subscription.ts +++ b/packages/datastore/src/sync/processors/subscription.ts @@ -28,7 +28,7 @@ import { ProcessName, SchemaModel, SchemaNamespace, -} from '~/types'; +} from '~/src/types'; import { RTFError, TransformerMutationType, @@ -39,9 +39,9 @@ import { getTokenForCustomAuth, getUserGroupsFromToken, predicateToGraphQLFilter, -} from '~/sync/utils'; -import { ModelPredicateCreator } from '~/predicates'; -import { validatePredicate } from '~/util'; +} from '~/src/sync/utils'; +import { ModelPredicateCreator } from '~/src/predicates'; +import { validatePredicate } from '~/src/util'; import { CONTROL_MSG as PUBSUB_CONTROL_MSG } from '@aws-amplify/api-graphql'; import { getSubscriptionErrorType } from './errorMaps'; diff --git a/packages/datastore/src/sync/processors/sync.ts b/packages/datastore/src/sync/processors/sync.ts index 4277414eacf..f54fa1d6ff9 100644 --- a/packages/datastore/src/sync/processors/sync.ts +++ b/packages/datastore/src/sync/processors/sync.ts @@ -14,7 +14,7 @@ import { PredicatesGroup, ProcessName, SchemaModel, -} from '~/types'; +} from '~/src/types'; import { buildGraphQLOperation, getClientSideAuthError, @@ -22,7 +22,7 @@ import { getModelAuthModes, getTokenForCustomAuth, predicateToGraphQLFilter, -} from '~/sync/utils'; +} from '~/src/sync/utils'; import { BackgroundProcessManager, Category, @@ -33,7 +33,7 @@ import { jitteredExponentialRetry, } from '@aws-amplify/core/internals/utils'; import { ConsoleLogger, Hub } from '@aws-amplify/core'; -import { ModelPredicateCreator } from '~/predicates'; +import { ModelPredicateCreator } from '~/src/predicates'; import { getSyncErrorType } from './errorMaps'; diff --git a/packages/datastore/src/sync/utils.ts b/packages/datastore/src/sync/utils.ts index ee7ceeb1cb7..2d4a4aa1b56 100644 --- a/packages/datastore/src/sync/utils.ts +++ b/packages/datastore/src/sync/utils.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { GraphQLAuthError } from '@aws-amplify/api'; import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils'; -import { ModelInstanceCreator } from '~/datastore/datastore'; +import { ModelInstanceCreator } from '~/src/datastore/datastore'; import { AuthModeStrategy, AuthorizationRule, @@ -31,12 +31,12 @@ import { isSchemaModel, isSchemaModelWithAttributes, isTargetNameAssociation, -} from '~/types'; +} from '~/src/types'; import { IDENTIFIER_KEY_SEPARATOR, establishRelationAndKeys, extractPrimaryKeyFieldNames, -} from '~/util'; +} from '~/src/util'; import { ConsoleLogger } from '@aws-amplify/core'; import { MutationEvent } from './'; diff --git a/packages/datastore/tsconfig.test.json b/packages/datastore/tsconfig.test.json index ea6be8e9a50..ab13dce0bd9 100644 --- a/packages/datastore/tsconfig.test.json +++ b/packages/datastore/tsconfig.test.json @@ -1,3 +1,7 @@ { - "extends": "./tsconfig.json" + "extends": "./tsconfig.json", + "compilerOptions": { + // TODO(test): enable noImplicitAny for tests + "noImplicitAny": false + } }