@aws-amplify/data-schema
Advanced tools
Comparing version 0.17.0 to 0.17.1
@@ -545,5 +545,5 @@ 'use strict'; | ||
*/ | ||
const secondaryIndexDefaultQueryField = (pk, sk) => { | ||
const secondaryIndexDefaultQueryField = (modelName, pk, sk) => { | ||
const skName = sk?.length ? 'And' + sk?.map(capitalize).join('And') : ''; | ||
const queryField = `listBy${capitalize(pk)}${skName}`; | ||
const queryField = `list${capitalize(modelName)}By${capitalize(pk)}${skName}`; | ||
return queryField; | ||
@@ -555,6 +555,6 @@ }; | ||
*/ | ||
const transformedSecondaryIndexesForModel = (secondaryIndexes) => { | ||
const transformedSecondaryIndexesForModel = (modelName, secondaryIndexes) => { | ||
const indexDirectiveWithAttributes = (partitionKey, sortKeys, indexName, queryField) => { | ||
if (!sortKeys.length && !indexName && !queryField) { | ||
return `@index(queryField: "${secondaryIndexDefaultQueryField(partitionKey)}")`; | ||
return `@index(queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey)}")`; | ||
} | ||
@@ -572,3 +572,3 @@ const attributes = []; | ||
else { | ||
attributes.push(`queryField: "${secondaryIndexDefaultQueryField(partitionKey, sortKeys)}"`); | ||
attributes.push(`queryField: "${secondaryIndexDefaultQueryField(modelName, partitionKey, sortKeys)}"`); | ||
} | ||
@@ -729,3 +729,3 @@ return `@index(${attributes.join(', ')})`; | ||
const [partitionKey] = identifier; | ||
const transformedSecondaryIndexes = transformedSecondaryIndexesForModel(typeDef.data.secondaryIndexes); | ||
const transformedSecondaryIndexes = transformedSecondaryIndexesForModel(typeName, typeDef.data.secondaryIndexes); | ||
const { authString, authFields } = calculateAuth(mostRelevantAuthRules); | ||
@@ -732,0 +732,0 @@ if (authString == '') { |
@@ -1,2 +0,1 @@ | ||
import { IsEmptyStringOrNever } from '@aws-amplify/data-schema-types'; | ||
import { ModelIndexType } from '../ModelIndex'; | ||
@@ -28,3 +27,4 @@ type ModelIndexTypeShape = ModelIndexType<any, any, any, any, any>; | ||
type SingleIndexIrFromType<Idx extends ModelIndexTypeShape, ResolvedFields> = Idx extends ModelIndexType<any, infer PK extends string, infer SK, infer QueryField extends string | never, any> ? { | ||
queryField: IsEmptyStringOrNever<QueryField> extends true ? `listBy${QueryFieldLabelFromTuple<SK, Capitalize<PK>>}` : QueryField; | ||
defaultQueryFieldSuffix: `${QueryFieldLabelFromTuple<SK, Capitalize<PK>>}`; | ||
queryField: QueryField; | ||
pk: PK extends keyof ResolvedFields ? { | ||
@@ -31,0 +31,0 @@ [Key in PK]: Exclude<ResolvedFields[PK], null>; |
@@ -1,2 +0,2 @@ | ||
import { DeepReadOnlyObject, UnwrapArray, UnionToIntersection, Prettify, Equal, ExtractModelMeta } from '@aws-amplify/data-schema-types'; | ||
import { DeepReadOnlyObject, UnwrapArray, UnionToIntersection, Prettify, Equal, ExtractModelMeta, IsEmptyStringOrNever } from '@aws-amplify/data-schema-types'; | ||
import type { Observable } from 'rxjs'; | ||
@@ -328,3 +328,3 @@ export { __modelMeta__, ExtractModelMeta, } from '@aws-amplify/data-schema-types'; | ||
}; | ||
export type ModelTypesClient<Model extends Record<string, unknown>, ModelMeta extends ModelMetaShape, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], Model> & { | ||
export type ModelTypesClient<ModelName extends string, Model extends Record<string, unknown>, ModelMeta extends ModelMetaShape, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], ModelName, Model> & { | ||
create: (model: Prettify<CreateModelInput<Model, ModelMeta>>, options?: { | ||
@@ -389,3 +389,3 @@ authMode?: AuthMode; | ||
}; | ||
type ModelTypesSSRCookies<Model extends Record<string, unknown>, ModelMeta extends ModelMetaShape, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], Model> & { | ||
type ModelTypesSSRCookies<ModelName extends string, Model extends Record<string, unknown>, ModelMeta extends ModelMetaShape, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], ModelName, Model> & { | ||
create: (model: Prettify<CreateModelInput<Model, ModelMeta>>, options?: { | ||
@@ -423,3 +423,3 @@ authMode?: AuthMode; | ||
}; | ||
type ModelTypesSSRRequest<Model extends Record<string, unknown>, ModelMeta extends ModelMetaShape, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], Model> & { | ||
type ModelTypesSSRRequest<ModelName extends string, Model extends Record<string, unknown>, ModelMeta extends ModelMetaShape, FlatModel extends Record<string, unknown> = ResolvedModel<Model>> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], ModelName, Model> & { | ||
create: (contextSpec: any, model: Prettify<CreateModelInput<Model, ModelMeta>>, options?: { | ||
@@ -459,3 +459,3 @@ authMode?: AuthMode; | ||
export type ModelTypes<Schema extends Record<any, any>, Context extends ContextType = 'CLIENT', ModelMeta extends Record<any, any> = ExtractModelMeta<Schema>> = { | ||
[ModelName in Exclude<keyof Schema, keyof CustomOperations<Schema, 'Mutation' | 'Query' | 'Subscription', Context, ModelMeta>>]: ModelName extends string ? Schema[ModelName] extends Record<string, unknown> ? Context extends 'CLIENT' ? ModelTypesClient<Schema[ModelName], ModelMeta[ModelName]> : Context extends 'COOKIES' ? ModelTypesSSRCookies<Schema[ModelName], ModelMeta[ModelName]> : Context extends 'REQUEST' ? ModelTypesSSRRequest<Schema[ModelName], ModelMeta[ModelName]> : never : never : never; | ||
[ModelName in Exclude<keyof Schema, keyof CustomOperations<Schema, 'Mutation' | 'Query' | 'Subscription', Context, ModelMeta>>]: ModelName extends string ? Schema[ModelName] extends Record<string, unknown> ? Context extends 'CLIENT' ? ModelTypesClient<ModelName, Schema[ModelName], ModelMeta[ModelName]> : Context extends 'COOKIES' ? ModelTypesSSRCookies<ModelName, Schema[ModelName], ModelMeta[ModelName]> : Context extends 'REQUEST' ? ModelTypesSSRRequest<ModelName, Schema[ModelName], ModelMeta[ModelName]> : never : never : never; | ||
}; | ||
@@ -525,2 +525,3 @@ export type CustomQueries<Schema extends Record<any, any>, Context extends ContextType = 'CLIENT', ModelMeta extends Record<any, any> = ExtractModelMeta<Schema>> = CustomOperations<Schema, 'Query', Context, ModelMeta>; | ||
export type SecondaryIndexIrShape = { | ||
defaultQueryFieldSuffix: string; | ||
queryField: string; | ||
@@ -534,20 +535,18 @@ pk: { | ||
}; | ||
type IndexQueryMethodsFromIR<SecondaryIdxTuple extends SecondaryIndexIrShape[], Model extends Record<string, unknown>, Res = unknown> = SecondaryIdxTuple extends [ | ||
type IndexQueryMethodsFromIR<SecondaryIdxTuple extends SecondaryIndexIrShape[], ModelName extends string, Model extends Record<string, unknown>, Res = unknown> = SecondaryIdxTuple extends [ | ||
infer A extends SecondaryIndexIrShape, | ||
...infer B extends SecondaryIndexIrShape[] | ||
] ? IndexQueryMethodsFromIR<B, Model, IndexQueryMethodSignature<A, Model> & Res> : Res; | ||
type IndexQueryMethodSignature<Idx extends SecondaryIndexIrShape, Model extends Record<string, unknown>> = { | ||
[K in Idx['queryField'] & string]: <FlatModel extends Record<string, unknown> = ResolvedModel<Model>, SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(input: Idx['pk'] & { | ||
[SKField in keyof Idx['sk']]+?: string extends Idx['sk'][SKField] ? StringFilter : NumericFilter; | ||
}, options?: { | ||
filter?: ModelFilter<Model>; | ||
sortDirection?: ModelSortDirection; | ||
limit?: number; | ||
nextToken?: string | null; | ||
selectionSet?: SelectionSet; | ||
authMode?: AuthMode; | ||
authToken?: string; | ||
headers?: CustomHeaders; | ||
}) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>; | ||
}; | ||
] ? IndexQueryMethodsFromIR<B, ModelName, Model, IndexQueryMethodSignature<A, ModelName, Model> & Res> : Res; | ||
type IndexQueryMethodSignature<Idx extends SecondaryIndexIrShape, ModelName extends string, Model extends Record<string, unknown>> = Record<IsEmptyStringOrNever<Idx['queryField']> extends false ? Idx['queryField'] : `list${ModelName}By${Idx['defaultQueryFieldSuffix']}`, <FlatModel extends Record<string, unknown> = ResolvedModel<Model>, SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(input: Idx['pk'] & { | ||
[SKField in keyof Idx['sk']]+?: string extends Idx['sk'][SKField] ? StringFilter : NumericFilter; | ||
}, options?: { | ||
filter?: ModelFilter<Model>; | ||
sortDirection?: ModelSortDirection; | ||
limit?: number; | ||
nextToken?: string | null; | ||
selectionSet?: SelectionSet; | ||
authMode?: AuthMode; | ||
authToken?: string; | ||
headers?: CustomHeaders; | ||
}) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>>; | ||
type FilteredKeys<T> = { | ||
@@ -554,0 +553,0 @@ [P in keyof T]: T[P] extends never ? never : P; |
{ | ||
"name": "@aws-amplify/data-schema", | ||
"version": "0.17.0", | ||
"version": "0.17.1", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -1,2 +0,1 @@ | ||
import { IsEmptyStringOrNever } from '@aws-amplify/data-schema-types'; | ||
import { ModelIndexType } from '../ModelIndex'; | ||
@@ -37,27 +36,24 @@ | ||
*/ | ||
type SingleIndexIrFromType< | ||
Idx extends ModelIndexTypeShape, | ||
ResolvedFields, | ||
> = Idx extends ModelIndexType< | ||
any, | ||
infer PK extends string, | ||
infer SK, | ||
infer QueryField extends string | never, | ||
any | ||
> | ||
? { | ||
queryField: IsEmptyStringOrNever<QueryField> extends true | ||
? `listBy${QueryFieldLabelFromTuple<SK, Capitalize<PK>>}` | ||
: QueryField; | ||
pk: PK extends keyof ResolvedFields | ||
? { | ||
[Key in PK]: Exclude<ResolvedFields[PK], null>; | ||
} | ||
: never; | ||
// distribute ResolvedFields over SK | ||
sk: unknown extends SK | ||
? never | ||
: ResolvedSortKeyFields<SK, ResolvedFields>; | ||
} | ||
: never; | ||
type SingleIndexIrFromType<Idx extends ModelIndexTypeShape, ResolvedFields> = | ||
Idx extends ModelIndexType< | ||
any, | ||
infer PK extends string, | ||
infer SK, | ||
infer QueryField extends string | never, | ||
any | ||
> | ||
? { | ||
defaultQueryFieldSuffix: `${QueryFieldLabelFromTuple<SK, Capitalize<PK>>}`; | ||
queryField: QueryField; | ||
pk: PK extends keyof ResolvedFields | ||
? { | ||
[Key in PK]: Exclude<ResolvedFields[PK], null>; | ||
} | ||
: never; | ||
// distribute ResolvedFields over SK | ||
sk: unknown extends SK | ||
? never | ||
: ResolvedSortKeyFields<SK, ResolvedFields>; | ||
} | ||
: never; | ||
@@ -64,0 +60,0 @@ /** |
@@ -11,2 +11,3 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
ExtractModelMeta, | ||
IsEmptyStringOrNever, | ||
} from '@aws-amplify/data-schema-types'; | ||
@@ -498,6 +499,7 @@ import type { Observable } from 'rxjs'; | ||
export type ModelTypesClient< | ||
ModelName extends string, | ||
Model extends Record<string, unknown>, | ||
ModelMeta extends ModelMetaShape, | ||
FlatModel extends Record<string, unknown> = ResolvedModel<Model>, | ||
> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], Model> & { | ||
> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], ModelName, Model> & { | ||
create: ( | ||
@@ -594,6 +596,7 @@ model: Prettify<CreateModelInput<Model, ModelMeta>>, | ||
type ModelTypesSSRCookies< | ||
ModelName extends string, | ||
Model extends Record<string, unknown>, | ||
ModelMeta extends ModelMetaShape, | ||
FlatModel extends Record<string, unknown> = ResolvedModel<Model>, | ||
> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], Model> & { | ||
> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], ModelName, Model> & { | ||
create: ( | ||
@@ -647,6 +650,7 @@ model: Prettify<CreateModelInput<Model, ModelMeta>>, | ||
type ModelTypesSSRRequest< | ||
ModelName extends string, | ||
Model extends Record<string, unknown>, | ||
ModelMeta extends ModelMetaShape, | ||
FlatModel extends Record<string, unknown> = ResolvedModel<Model>, | ||
> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], Model> & { | ||
> = IndexQueryMethodsFromIR<ModelMeta['secondaryIndexes'], ModelName, Model> & { | ||
create: ( | ||
@@ -723,7 +727,15 @@ // TODO: actual type | ||
? Context extends 'CLIENT' | ||
? ModelTypesClient<Schema[ModelName], ModelMeta[ModelName]> | ||
? ModelTypesClient<ModelName, Schema[ModelName], ModelMeta[ModelName]> | ||
: Context extends 'COOKIES' | ||
? ModelTypesSSRCookies<Schema[ModelName], ModelMeta[ModelName]> | ||
? ModelTypesSSRCookies< | ||
ModelName, | ||
Schema[ModelName], | ||
ModelMeta[ModelName] | ||
> | ||
: Context extends 'REQUEST' | ||
? ModelTypesSSRRequest<Schema[ModelName], ModelMeta[ModelName]> | ||
? ModelTypesSSRRequest< | ||
ModelName, | ||
Schema[ModelName], | ||
ModelMeta[ModelName] | ||
> | ||
: never | ||
@@ -855,2 +867,3 @@ : never | ||
export type SecondaryIndexIrShape = { | ||
defaultQueryFieldSuffix: string; | ||
queryField: string; | ||
@@ -863,2 +876,3 @@ pk: { [key: string]: string | number }; | ||
SecondaryIdxTuple extends SecondaryIndexIrShape[], | ||
ModelName extends string, | ||
Model extends Record<string, unknown>, | ||
@@ -870,3 +884,8 @@ Res = unknown, // defaulting `unknown` because it gets absorbed in an intersection, e.g. `{a: 1} & unknown` => `{a: 1}` | ||
] | ||
? IndexQueryMethodsFromIR<B, Model, IndexQueryMethodSignature<A, Model> & Res> | ||
? IndexQueryMethodsFromIR< | ||
B, | ||
ModelName, | ||
Model, | ||
IndexQueryMethodSignature<A, ModelName, Model> & Res | ||
> | ||
: Res; | ||
@@ -876,5 +895,9 @@ | ||
Idx extends SecondaryIndexIrShape, | ||
ModelName extends string, | ||
Model extends Record<string, unknown>, | ||
> = { | ||
[K in Idx['queryField'] & string]: < | ||
> = Record< | ||
IsEmptyStringOrNever<Idx['queryField']> extends false | ||
? Idx['queryField'] | ||
: `list${ModelName}By${Idx['defaultQueryFieldSuffix']}`, | ||
< | ||
FlatModel extends Record<string, unknown> = ResolvedModel<Model>, | ||
@@ -898,4 +921,4 @@ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[], | ||
}, | ||
) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>; | ||
}; | ||
) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>> | ||
>; | ||
@@ -902,0 +925,0 @@ type FilteredKeys<T> = { |
@@ -813,2 +813,3 @@ import { type CustomPathData, type InternalSchema } from './ModelSchema'; | ||
const secondaryIndexDefaultQueryField = ( | ||
modelName: string, | ||
pk: string, | ||
@@ -819,3 +820,3 @@ sk?: readonly string[], | ||
const queryField = `listBy${capitalize(pk)}${skName}`; | ||
const queryField = `list${capitalize(modelName)}By${capitalize(pk)}${skName}`; | ||
@@ -830,2 +831,3 @@ return queryField; | ||
const transformedSecondaryIndexesForModel = ( | ||
modelName: string, | ||
secondaryIndexes: readonly InternalModelIndexType[], | ||
@@ -841,2 +843,3 @@ ): TransformedSecondaryIndexes => { | ||
return `@index(queryField: "${secondaryIndexDefaultQueryField( | ||
modelName, | ||
partitionKey, | ||
@@ -863,2 +866,3 @@ )}")`; | ||
`queryField: "${secondaryIndexDefaultQueryField( | ||
modelName, | ||
partitionKey, | ||
@@ -1172,2 +1176,3 @@ sortKeys, | ||
const transformedSecondaryIndexes = transformedSecondaryIndexesForModel( | ||
typeName, | ||
typeDef.data.secondaryIndexes, | ||
@@ -1174,0 +1179,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1836457
20634