-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Hi,
Basically follow the instruction and create a really large model generate from a database.
Then attempt to set the Relationships and basically the whole frontend client types generation falls over, because
they can't complete the evaluation of anything, everything just keeps falling over as keep shitting the TS 50 recursive limit.
"@aws-amplify/data-schema": "^1.20.3",
I would like to propose that you fix this. I was looking at making a pull request with the fix, I was about 97% of the way there. I wanted to avoid using your SetSubArg, which results in type re-writes, instead just merging two dataset to gather of the final results, because should be faster, but you see there some issues with that, because typescript then seem to not work well with that, which I put down possible to things not being allowed to happen across files different levels of files and libraries, as to remain or be done in the same Library from my un wrapping of things.
Proposed fix, make sure you merge dataset and then use dictionary looks instead rather capture things using keys, that immediate look up the results instead that horrible ghastly array iteration that gets slow and slow with each new model added.
Case ID:176768433200003, sent you some private zip models examples of everything include node_modules to files I changed about a year ago, but I didn't have time to look at this again, where was left as found new way to fix things, just don't use setRelationships, I just put directly into the models, like do for dynamo db, which avoid the Nmodel X Nmodel computation time and ts limit being hit.
Additional to learn about typing's and previous attempts at doing things like this, which work out far better and faster and better typing control of modifiers extra, please look to what I did for mongo to infer everything. Done in 2019
https://github.com/wesleyolis/mongooseRelationalTypes -refactored again, to not use extends as it was slow... use 2.6 hack
https://github.com/wesleyolis/mongooseRelationTypesPoorPerformance
https://github.com/wesleyolis/tsTypesFromASchemaImplemention
const schemaSQL2 = setRelationshipsObject(schemaSQL1,(models) => {
return {
Catalogue: models.Catalogue.relationships({
Categorys: a.hasMany("CatalogueCategory", "CatalogueID"),
}),
CatalogueCategory: models.CatalogueCategory.relationships({
Catalogues: a.belongsTo("Catalogue", "CatalogueID"),
Categorys: a.belongsTo("Category", "CategoryID")
}),
ProductCharacteristics: models.ProductCharacteristics.relationships({
ProductSpesification: a.belongsTo("ProductSpesification","ProductSpesificationID"),
ProductCharacteristicsValues: a.hasMany("ProductCharacteristicsValue","ProductCharacteristicsID")
}),
ProductCharacteristic: models.ProductCharacteristicsValue.relationships({
ProductCharacteristic: a.belongsTo("ProductCharacteristics","ProductCharacteristicsID")
}),
};
})
type SchemaSQLUnitTest33 = ClientSchema<typeof schemaSQL2>
type genClientSchemaSQL33 = V6Client<SchemaSQLUnitTest33, DefaultCommonClientOptions>;
const test3: genClientSchemaSQL33
test3.models.ProductCharacteristics.list().then(r => {
})Attempts to post fix this, but because alot of your types are not export that is problem and ment I had to edit your types directly.
type ModelRelationshipFieldParamShape = {
type: 'model';
relationshipType: string;
relatedModel: string;
array: boolean;
valueRequired: boolean;
references: string[];
arrayRequired: boolean;
};
type TModelWithRelationShips<T extends any> = {
[TypeKey in keyof T]: {
relationships<Param extends Partial<Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>>>(relationships: Param): Record<TypeKey, Param>
//relationships<Param extends Partial<Record<`${keyof T & string}s` | `${keyof T & string}`, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>>>(relationships: Param): Record<TypeKey, Param>
};
}
export interface PrimaryIndexIrShape {
pk: {
[key: string]: string | number;
};
sk: {
[key: string]: string | number;
} | never;
compositeSk: never | string;
}
export interface SecondaryIndexIrShape extends PrimaryIndexIrShape {
defaultQueryFieldSuffix: string;
queryField: string;
}
export type DisableOperationsOptions = 'queries' | 'mutations' | 'subscriptions' | 'list' | 'get' | 'create' | 'update' | 'delete' | 'onCreate' | 'onUpdate' | 'onDelete';
export type ModelTypeParamShapeCus = {
fields: ModelFields;
identifier: PrimaryIndexIrShape;
secondaryIndexes: ReadonlyArray<SecondaryIndexIrShape>;
authorization: Authorization<any, any, any>[];
disabledOperations: ReadonlyArray<DisableOperationsOptions>;
};
type ModelTypeParamNew<
TModelFields extends ModelFields,
TPrimaryIndexIrShape extends PrimaryIndexIrShape,
TSecondaryIndexIrShape extends ReadonlyArray<SecondaryIndexIrShape>,
TAuthorization extends Authorization<any, any, any>[],
TDisableOperationsOptions extends ReadonlyArray<DisableOperationsOptions>
> = {
fields: TModelFields;
identifier: TPrimaryIndexIrShape;
secondaryIndexes: TSecondaryIndexIrShape;
authorization: TAuthorization;
disabledOperations: TDisableOperationsOptions;
};
type ModelSchemaContents = Record<string, any>;
type ModelSchemaParamShapeV2<
Types extends ModelSchemaContents = ModelSchemaContents,
TSchemaAuthorization = unknown, //extends any, SchemaAuthorization<any, any, any>[] = SchemaAuthorization<any, any, any>[],
TSchemaConfiguration = unknown //extends any, SchemaConfiguration<any, any> = SchemaConfiguration<any, any>
>= {
types: Types;
authorization: TSchemaAuthorization;
configuration: TSchemaConfiguration;
};
/*
export type AddRelationshipFieldsToModelTypeFields<Model, RelationshipFields extends
Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>> = Model extends
ModelType<infer ModelParam extends ModelTypeParamShape, infer HiddenKeys>
? ModelType<SetTypeSubArg<ModelParam, 'fields', ModelParam['fields'] & RelationshipFields>, HiddenKeys> : never;
*/
type ModelWithRelationships<Types extends Record<any, any>, RelationshipsMap extends Record<any, any>,
InterectKeys extends keyof Types = keyof RelationshipsMap & keyof Types,
//RemaningKeys extends keyof Types = Exclude<keyof Types, InterectKeys>
> =
{
[k in InterectKeys]: Types[k] extends ModelType<infer ModelParams, infer HiddenKeys> ?
//ModelParams extends ModelTypeParamNew<infer TFields extends ModelFields, infer Tidentifier, infer TsecondaryIndexes,infer Tauthorization, infer TdisabledOperations>
//?
//ModelType<ModelParams,HiddenKeys>
//{sdfs:'sdfsdf'}
ModelType<SetTypeSubArg<ModelParams, 'fields', ModelParams['fields'] & RelationshipsMap[k]>, HiddenKeys>
//:{sdfs:'sdfsdfsdfsdf'}
//extends ModelTypeParamShape
//ModelParams['fields']
/*
ModelType<
ModelTypeParamNew<ModelParams['fields'] & RelationshipsMap[k], ModelParams['identifier'],
ModelParams['secondaryIndexes'], ModelParams['authorization'], ModelParams['disabledOperations']>, HiddenKeys>
:'sdfsdf'
*/
/*
ModelType<
ModelTypeParamNew<
{
fields: ModelParams['fields'] & RelationshipsMap[k],
identifier: ModelParams['identifier'],
secondaryIndexes: ModelParams['secondaryIndexes'],
authorization: ModelParams['authorization'],
disabledOperations: ModelParams['disabledOperations']
} , HiddenKeys>
*/
:{sdfs:'sdfsdfsdfsdf'}
}
&
{
[k in Exclude<keyof Types, InterectKeys>] : Types[k]
};
type RelationshipTemplate = Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>;ModelSchema.d.ts
export type RDSModelSchemaParamShape = ModelSchemaParamShape;
export type InternalSchema = {
data: {
types: InternalSchemaModels;
authorization: SchemaAuthorization<any, any, any>[];
configuration: SchemaConfiguration<any, any>;
};
context?: {
schemas: InternalSchema[];
};
};
export type BaseSchema<T extends ModelSchemaParamShape, IsRDS extends boolean = false> = {
data: T;
models:
{
[TypeKey in keyof T['types']]: T['types'][TypeKey] extends BaseModelType ? SchemaModelType<T['types'][TypeKey], TypeKey & string, IsRDS> : never;
};
transform: () => DerivedApiDefinition;
context?: {
schemas: GenericModelSchema<any>[];
};
};
export type GenericModelSchema<T extends ModelSchemaParamShape> = BaseSchema<T> & Brand<typeof rdsSchemaBrandName | typeof ddbSchemaBrandName>;
/**
* Model schema definition interface
*
* @param T - The shape of the model schema
* @param UsedMethods - The method keys already defined
*/
export type ModelSchema<T extends ModelSchemaParamShape, UsedMethods extends 'authorization' | 'relationships' = never> = Omit<{
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => ModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
}, UsedMethods> & BaseSchema<T> & DDBSchemaBrand;
type RDSModelSchemaFunctions = 'addToSchema' | 'addQueries' | 'addMutations' | 'addSubscriptions' | 'authorization' | 'setRelationships' | 'setAuthorization' | 'renameModelFields' | 'renameModels';
type OmitFromEach<Models, Modifier extends string> = {
[ModelName in keyof Models]: Omit<Models[ModelName], Modifier>;
};
type RelationshipTemplate = Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>;
/**
* RDSModel schema definition interface
*
* @param T - The shape of the RDS model schema
* @param UsedMethods - The method keys already defined
*/
export type RDSModelSchema<T extends RDSModelSchemaParamShape, UsedMethods extends RDSModelSchemaFunctions = never> = Omit<{
addToSchema: <AddedTypes extends AddToSchemaContents>(types: AddedTypes) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & AddedTypes>, UsedMethods | 'addToSchema'>;
/**
* @deprecated use `addToSchema()` to add operations to a SQL schema
*/
addQueries: <Queries extends Record<string, QueryCustomOperation>>(types: Queries) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Queries>, UsedMethods | 'addQueries'>;
/**
* @deprecated use `addToSchema()` to add operations to a SQL schema
*/
addMutations: <Mutations extends Record<string, MutationCustomOperation>>(types: Mutations) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Mutations>, UsedMethods | 'addMutations'>;
/**
* @deprecated use `addToSchema()` to add operations to a SQL schema
*/
addSubscriptions: <Subscriptions extends Record<string, SubscriptionCustomOperation>>(types: Subscriptions) => RDSModelSchema<SetTypeSubArg<T, 'types', T['types'] & Subscriptions>, UsedMethods | 'addSubscriptions'>;
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(callback: (allow: AllowModifier) => AuthRules | AuthRules[]) => RDSModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
setAuthorization: (callback: (models: OmitFromEach<BaseSchema<T, true>['models'], 'secondaryIndexes'>, schema: RDSModelSchema<T, UsedMethods | 'setAuthorization'>) => void) => RDSModelSchema<T>;
setRelationships: <Relationships extends ReadonlyArray<Partial<Record<keyof T['types'], RelationshipTemplate>>>>(
callback: (models: OmitFromEach<BaseSchema<T, true>['models'], 'authorization' | 'fields' | 'secondaryIndexes'>) => Relationships) =>
RDSModelSchema<SetTypeSubArg<T, 'types', {
[ModelName in keyof T['types']]: ModelWithRelationships<T['types'], Relationships, ModelName>;
}>, UsedMethods | 'setRelationships'>;
renameModels: <NewName extends string, CurName extends string = keyof BaseSchema<T>['models'] & string, const ChangeLog extends readonly [CurName, NewName][] = []>(callback: () => ChangeLog) => RDSModelSchema<SetTypeSubArg<T, 'types', RenameUsingTuples<T['types'], ChangeLog>>, UsedMethods | 'renameModels'>;
}, UsedMethods> & BaseSchema<T, true> & RDSSchemaBrand;
/**
* Amplify API Next Model Schema shape
*/
export type ModelSchemaType = ModelSchema<ModelSchemaParamShape>;
type ModelSchemaParamShapeV2<
Types extends ModelSchemaContents = ModelSchemaContents,
TSchemaAuthorization = unknown, //extends any, SchemaAuthorization<any, any, any>[] = SchemaAuthorization<any, any, any>[],
TSchemaConfiguration = unknown //extends any, SchemaConfiguration<any, any> = SchemaConfiguration<any, any>
>= {
types: Types;
authorization: TSchemaAuthorization;
configuration: TSchemaConfiguration;
};
type TModelWithRelationShips<T extends any> = {
[TypeKey in keyof T]: {
relationships<Param extends Partial<Record<string,
ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>>>(relationships: Param): Record<TypeKey, Param>
//relationships<Param extends Partial<Record<`${keyof T & string}s` | `${keyof T & string}`, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>>>(relationships: Param): Record<TypeKey, Param>
};
}
type TModelWithRelationShips2<T extends any> = {
[TypeKey in keyof T]: {
relationships<Param extends Record<string,
OmitFromEach<BaseSchema<T, true>['models'], 'authorization' | 'fields' | 'secondaryIndexes'>
//ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>
>>(relationships: Param): Record<TypeKey, Param>
//relationships<Param extends Partial<Record<`${keyof T & string}s` | `${keyof T & string}`, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>>>(relationships: Param): Record<TypeKey, Param>
};
}
export function setRelationshipsObject2<TModel extends {data: {
types: any;
authorization: any;
configuration: any;
}},
T extends RDSModelSchemaParamShape = TModel['data'],
Param extends Record<string,OmitFromEach<BaseSchema<T, true>['models'], 'authorization' | 'fields' | 'secondaryIndexes'>>
> (model: TModel, relationships: (models: OmitFromEach<BaseSchema<T, true>['models'], 'authorization' | 'fields' | 'secondaryIndexes'>) => Relationships)
//ModelWithRelationshipsV3<TTypes, TRelationships>
//RDSModelSchema<ModelSchemaParamShapeV2<ModelWithRelationshipsV4<TTypes, TRelationships>, TModel['data']['authorization'], TModel['data']['configuration']>>
RDSModelSchema<SetTypeSubArg<T, 'types', {[ModelName in keyof T['types']]: ModelWithRelationships<T['types'], Relationships, ModelName>;}>, UsedMethods | 'setRelationships'>
//RDSModelSchema<TResult>
{
return (model as any).setRelationships(Object.values(obj));
}
export function setRelationshipsObject<TModel extends {data: {
types: any;
authorization: any;
configuration: any;
}},
TRelationships extends Partial<Record<keyof TTypes, any>>,
TTypes extends Record<any,any> = TModel['data']['types'],
TModelTrans = TModelWithRelationShips<TTypes>,
//TResult extends ModelSchemaParamShapeV2<any,any,any> =
//ModelSchemaParamShapeV2<ModelWithRelationshipsV2<TTypes, TRelationships>, TModel['data']['authorization'], TModel['data']['configuration']>
>(model: TModel, obj:(model:TModelTrans) => TRelationships) :
//ModelWithRelationshipsV3<TTypes, TRelationships>
//RDSModelSchema<ModelSchemaParamShapeV2<ModelWithRelationshipsV4<TTypes, TRelationships>, TModel['data']['authorization'], TModel['data']['configuration']>>
RDSModelSchema<SetTypeSubArg<TModel['data'], 'types', ModelWithRelationshipsV4<TTypes, TRelationships>>, UsedMethods | 'setRelationships'>
//RDSModelSchema<TResult>
{
return (model as any).setRelationships(Object.values(obj));
}
/*
callback: (models: OmitFromEach<BaseSchema<T, true>['models'], 'authorization' | 'fields' | 'secondaryIndexes'>) => Relationships) => RDSModelSchema<SetTypeSubArg<T, 'types', {
[ModelName in keyof T['types']]: ModelWithRelationships<T['types'], Relationships, ModelName>;
*/
export type ModelWithRelationshipsV4<Types extends Record<any, any>, RelationshipsMap extends Record<any, any>,
InterectKeys extends keyof Types = keyof RelationshipsMap & keyof Types,
//RemaningKeys extends keyof Types = Exclude<keyof Types, InterectKeys>
> =
{
[k in keyof Types]: Types[k] extends ModelType<infer ModelParam extends ModelTypeParamShape, infer HiddenKeys> ?
AddRelationshipFieldsToModelTypeFieldsV2<Types[k], RelationshipsMap>
: Types[k]
}
/* &
{
[k in Exclude<keyof Types, InterectKeys>] : Types[k]
};
*/
/*
export type AddRelationshipFieldsToModelTypeFields<Model, RelationshipFields extends
Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>> = Model extends
ModelType<infer ModelParam extends ModelTypeParamShape, infer HiddenKeys>
? ModelType<SetTypeSubArg<ModelParam, 'fields', ModelParam['fields'] & RelationshipFields>, HiddenKeys> : never;
*/
export type ModelWithRelationshipsV3<Types extends Record<any, any>, RelationshipsMap extends Record<any, any>,
InterectKeys extends keyof Types = keyof RelationshipsMap & keyof Types,
//RemaningKeys extends keyof Types = Exclude<keyof Types, InterectKeys>
> =
{
[k in InterectKeys]: Types[k] extends ModelType<infer ModelParam extends ModelTypeParamShape, infer HiddenKeys> ?
//ModelParams extends ModelTypeParamNew<infer TFields extends ModelFields, infer Tidentifier, infer TsecondaryIndexes,infer Tauthorization, infer TdisabledOperations>
//?
//ModelType<ModelParams,HiddenKeys>
//{sdfs:'sdfsdf'}
//AddRelationshipFieldsToModelTypeFields<Types[ModelName], RelationshipMap[ModelName]>
AddRelationshipFieldsToModelTypeFieldsV2<Types[k], RelationshipsMap>
//ModelType<SetTypeSubArg<ModelParams, 'fields', ModelParams['fields'] & RelationshipsMap[k]>, HiddenKeys>
//:{sdfs:'sdfsdfsdfsdf'}
//extends ModelTypeParamShape
//ModelParams['fields']
/*
ModelType<
ModelTypeParamNew<ModelParams['fields'] & RelationshipsMap[k], ModelParams['identifier'],
ModelParams['secondaryIndexes'], ModelParams['authorization'], ModelParams['disabledOperations']>, HiddenKeys>
:'sdfsdf'
*/
/*
ModelType<
ModelTypeParamNew<
{
fields: ModelParams['fields'] & RelationshipsMap[k],
identifier: ModelParams['identifier'],
secondaryIndexes: ModelParams['secondaryIndexes'],
authorization: ModelParams['authorization'],
disabledOperations: ModelParams['disabledOperations']
} , HiddenKeys>
*/
:Types[k]
}
&
{
[k in Exclude<keyof Types, InterectKeys>] : Types[k]
};
type ModelWithRelationshipsV2<Types extends Record<string, any>, Relationships extends ReadonlyArray<Record<string, RelationshipTemplate | undefined>>,
ModelName extends keyof Types, RelationshipMap extends UnionToIntersection<Relationships[number]> =
UnionToIntersection<Relationships[number]>> = ModelName extends keyof RelationshipMap ?
RelationshipMap[ModelName] extends Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>> ?
AddRelationshipFieldsToModelTypeFields<Types[ModelName], RelationshipMap[ModelName]> : Types[ModelName] : Types[ModelName];
type ModelWithRelationships<Types extends Record<string, any>, Relationships extends ReadonlyArray<Record<string, RelationshipTemplate | undefined>>,
ModelName extends keyof Types, RelationshipMap extends UnionToIntersection<Relationships[number]> =
UnionToIntersection<Relationships[number]>> = ModelName extends keyof RelationshipMap ?
RelationshipMap[ModelName] extends Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>> ?
AddRelationshipFieldsToModelTypeFields<Types[ModelName], RelationshipMap[ModelName]> : Types[ModelName] : Types[ModelName];ModelTypes.d.ts
import type { SetTypeSubArg } from '@aws-amplify/data-schema-types';
import { type PrimaryIndexIrShape, type SecondaryIndexIrShape } from './util';
import type { InternalField, BaseModelField } from './ModelField';
import type { ModelRelationshipField, InternalRelationshipField, ModelRelationshipFieldParamShape } from './ModelRelationshipField';
import { type Authorization, type BaseAllowModifier, type AnyAuthorization } from './Authorization';
import type { RefType, RefTypeParamShape } from './RefType';
import type { EnumType } from './EnumType';
import type { CustomType, CustomTypeParamShape } from './CustomType';
import { type ModelIndexType, type InternalModelIndexType } from './ModelIndex';
import type { PrimaryIndexFieldsToIR, SecondaryIndexToIR } from './MappedTypes/MapIndexes';
import type { brandSymbol } from './util/Brand.js';
import type { methodKeyOf } from './util/usedMethods.js';
declare const brandName = "modelType";
export type deferredRefResolvingPrefix = 'deferredRefResolving:';
type ModelFields = Record<string, BaseModelField | ModelRelationshipField<any, string, any, any> | RefType<any, any, any> | EnumType | CustomType<CustomTypeParamShape>>;
type InternalModelFields = Record<string, InternalField | InternalRelationshipField>;
export type DisableOperationsOptions = 'queries' | 'mutations' | 'subscriptions' | 'list' | 'get' | 'create' | 'update' | 'delete' | 'onCreate' | 'onUpdate' | 'onDelete';
type ModelData = {
fields: ModelFields;
identifier: ReadonlyArray<string>;
secondaryIndexes: ReadonlyArray<ModelIndexType<any, any, any, any, any>>;
authorization: Authorization<any, any, any>[];
disabledOperations: ReadonlyArray<DisableOperationsOptions>;
};
type InternalModelData = ModelData & {
fields: InternalModelFields;
identifier: ReadonlyArray<string>;
secondaryIndexes: ReadonlyArray<InternalModelIndexType>;
authorization: Authorization<any, any, any>[];
disabledOperations: ReadonlyArray<DisableOperationsOptions>;
originalName?: string;
};
export type ModelTypeParamShape = {
fields: ModelFields;
identifier: PrimaryIndexIrShape;
secondaryIndexes: ReadonlyArray<SecondaryIndexIrShape>;
authorization: Authorization<any, any, any>[];
disabledOperations: ReadonlyArray<DisableOperationsOptions>;
};
/**
* Extract fields that are eligible to be PK or SK fields with their resolved type.
*
* Eligible fields include:
* 1. ModelField that contains string or number
* 2. inline EnumType
* 3. RefType that refers to a top level defined EnumType (this is enforced by
* validation that happens in the Schema Processor)
*
* NOTE: at this point, there is no way to resolve the type from a RefType as
* we don't have access to the NonModelType at this location. So we generate am
* indicator string, and resolve its corresponding type later in
* packages/data-schema/src/runtime/client/index.ts
*/
export type ExtractSecondaryIndexIRFields<T extends ModelTypeParamShape> = {
[FieldProp in keyof T['fields'] as T['fields'][FieldProp] extends BaseModelField<infer R> ? NonNullable<R> extends string | number ? FieldProp : never : T['fields'][FieldProp] extends EnumType | RefType<RefTypeParamShape, any, any> ? FieldProp : never]: T['fields'][FieldProp] extends BaseModelField<infer R> ? R : T['fields'][FieldProp] extends EnumType<infer values> ? values[number] : T['fields'][FieldProp] extends RefType<infer R, any, any> ? `${deferredRefResolvingPrefix}${R['link']}` : never;
};
export type AddRelationshipFieldsToModelTypeFields<Model, RelationshipFields extends Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>>
= Model extends ModelType<infer ModelParam extends ModelTypeParamShape, infer HiddenKeys> ?
ModelType<SetTypeSubArg<ModelParam, 'fields', ModelParam['fields'] & RelationshipFields>, HiddenKeys> : never;
type ModelTypeParamNew<
TModelFields,// extends ModelFields,
TPrimaryIndexIrShape,// extends PrimaryIndexIrShape,
TSecondaryIndexIrShape,// extends ReadonlyArray<SecondaryIndexIrShape>,
TAuthorization,// extends Authorization<any, any, any>[],
TDisableOperationsOptions,// extends ReadonlyArray<DisableOperationsOptions>
> = {
fields: TModelFields;
identifier: TPrimaryIndexIrShape;
secondaryIndexes: TSecondaryIndexIrShape;
authorization: TAuthorization;
disabledOperations: TDisableOperationsOptions;
};
export type AddRelationshipFieldsToModelTypeFieldsV2<Model,
RelationshipFields extends Record<string, ModelRelationshipField<ModelRelationshipFieldParamShape, string, any, any>>>
= Model extends ModelType<infer ModelParams extends ModelTypeParamShape, infer HiddenKeys> ?
/*
ModelType<ModelTypeParamNew<ModelParams['fields'] & RelationshipsMap[k],ModelParams['identifier'], ModelParams['secondaryIndexes'],
ModelParams['authorization'],ModelParams['disabledOperations']>, HiddenKeys>
*/
/*
ModelType<
{
fields: ModelParams['fields'] & RelationshipsMap[k],
identifier: ModelParams['identifier'],
secondaryIndexes: ModelParams['secondaryIndexes'],
authorization: ModelParams['authorization'],
disabledOperations: ModelParams['disabledOperations']
} , HiddenKeys>
*/
ModelType<SetTypeSubArg<ModelParams, 'fields', ModelParams['fields'] & RelationshipFields>, HiddenKeys>
: never;
export type BaseModelType<T extends ModelTypeParamShape = ModelTypeParamShape> = ModelType<T, UsableModelTypeKey>;
export type UsableModelTypeKey = methodKeyOf<ModelType>;
/**
* Model type definition interface
*
* @param T - The shape of the model type
* @param UsedMethod - The method keys already defined
*/
export type ModelType<T extends ModelTypeParamShape = ModelTypeParamShape, UsedMethod extends UsableModelTypeKey = never> = Omit<{
[brandSymbol]: typeof brandName;
/**
* Defines single-field or composite identifiers, the fields must be marked required
*
* @param identifier A list of field names used as identifiers for the data model
* @returns A ModelType instance with updated identifiers
*
* @example
* a.model({
* name: a.string().required(),
* email: a.string().required(),
* age: a.integer(),
* }).identifier(['name', 'email'])
*/
identifier<PrimaryIndexFields = ExtractSecondaryIndexIRFields<T>, PrimaryIndexPool extends string = keyof PrimaryIndexFields & string, const ID extends ReadonlyArray<PrimaryIndexPool> = readonly [], const PrimaryIndexIR extends PrimaryIndexIrShape = PrimaryIndexFieldsToIR<ID, PrimaryIndexFields>>(identifier: ID): ModelType<SetTypeSubArg<T, 'identifier', PrimaryIndexIR>, UsedMethod | 'identifier'>;
/**
* Adds secondary index for a model, secondary index consists of a "hash key" and optionally, a "sort key"
*
* @param callback A function that specifies "hash key" and "sort key"
* @returns A ModelType instance with updated secondary index
*
* @example
* a.model().secondaryIndexes((index) => [index('type').sortKeys(['sort'])])
*
* @see [Amplify documentation for secondary indexes](https://docs.amplify.aws/react/build-a-backend/data/data-modeling/secondary-index/)
* @see [Amazon DynamoDB documentation for secondary indexes](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html)
*/
secondaryIndexes<const SecondaryIndexFields = ExtractSecondaryIndexIRFields<T>, const SecondaryIndexPKPool extends string = keyof SecondaryIndexFields & string, const Indexes extends readonly ModelIndexType<string, string, unknown, readonly [], any>[] = readonly [], const IndexesIR extends readonly any[] = SecondaryIndexToIR<Indexes, SecondaryIndexFields>>(callback: (index: <PK extends SecondaryIndexPKPool>(pk: PK) => ModelIndexType<SecondaryIndexPKPool, PK, ReadonlyArray<Exclude<SecondaryIndexPKPool, PK>>>) => Indexes): ModelType<SetTypeSubArg<T, 'secondaryIndexes', IndexesIR>, UsedMethod | 'secondaryIndexes'>;
/**
* Disables the specified operations for the model
*
* @param ops A list of operations to be disabled
* @returns A ModelType instance with updated disabled operations
*
* @example
* a.model().disableOperations(['delete', 'update', 'queries', 'subscriptions'])
*
* @see [Amplify Data documentation for supported operations](https://docs.amplify.aws/react/build-a-backend/data/)
*/
disableOperations<const Ops extends ReadonlyArray<DisableOperationsOptions>>(ops: Ops): ModelType<SetTypeSubArg<T, 'disabledOperations', Ops>, UsedMethod | 'disableOperations'>;
/**
* Configures authorization rules for public, signed-in user, per user, and per user group data access
*
* @param callback A function that receives an allow modifier to define authorization rules
* @returns A ModelType instance with updated authorization rules
*
* @example
* a.model().authorization((allow) => [
* allow.guest(),
* allow.publicApiKey(),
* allow.authenticated(),
* ])
*/
authorization<AuthRuleType extends AnyAuthorization>(callback: (allow: BaseAllowModifier) => AuthRuleType | AuthRuleType[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, UsedMethod | 'authorization'>;
}, UsedMethod>;
/**
* External representation of Model Type that exposes the `relationships` modifier.
* Used on the complete schema object.
*/
export type SchemaModelType<T extends BaseModelType = ModelType<ModelTypeParamShape, 'identifier'>, ModelName extends string = string, IsRDS extends boolean = false> = IsRDS extends true ? T & {
relationships<Param extends Record<string, ModelRelationshipField<any, string, any, any>> = Record<never, never>>(relationships: Param): Record<ModelName, Param>;
fields: T extends ModelType<infer R, any> ? R['fields'] : never;
} : T;
/**
* Internal representation of Model Type that exposes the `data` property.
* Used at buildtime.
*/
export type InternalModel = SchemaModelType<ModelType<ModelTypeParamShape>, string, true> & {
data: InternalModelData;
};
/**
* Model Type type guard
* @param modelType - api-next ModelType
* @returns true if the given value is a ModelSchema
*/
export declare const isSchemaModelType: (modelType: any | SchemaModelType) => modelType is SchemaModelType;
/**
* Model default identifier
*
* @param pk - primary key
* @param sk - secondary key
* @param compositeSk - composite secondary key
*/
export type ModelDefaultIdentifier = {
pk: {
readonly id: string;
};
sk: never;
compositeSk: never;
};
/**
* A data model that creates a matching Amazon DynamoDB table and provides create, read (list and get), update,
* delete, and subscription APIs.
*
* @param fields database table fields. Supports scalar types and relationship types.
* @returns a data model definition
*/
export declare function model<T extends ModelFields>(fields: T): ModelType<{
fields: T;
identifier: ModelDefaultIdentifier;
secondaryIndexes: [];
authorization: [];
disabledOperations: [];
}>;
export {};
``