@aws-amplify/data-schema
Advanced tools
Comparing version 0.13.15 to 0.13.16
@@ -7,3 +7,3 @@ import { type __modelMeta__ } from '@aws-amplify/data-schema-types'; | ||
import type { ExtractNonModelTypes, NonModelTypesShape } from './MappedTypes/ExtractNonModelTypes'; | ||
import type { ResolveCustomOperations } from './MappedTypes/CustomOperations'; | ||
import { ResolveCustomOperations, CustomOperationHandlerTypes } from './MappedTypes/CustomOperations'; | ||
export type ClientSchema<Schema extends ModelSchema<any, any>> = InternalClientSchema<Schema>; | ||
@@ -32,5 +32,5 @@ /** | ||
}; | ||
}, ResolvedFields extends Record<string, unknown> = ResolveFieldProperties<Schema, NonModelTypes, ImplicitModels>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, SecondaryIndexes extends Record<string, any> = ModelSecondaryIndexes<SchemaTypes<Schema>>> = ResolvedFields & { | ||
}, ResolvedFields extends Record<string, unknown> = ResolveFieldProperties<Schema, NonModelTypes, ImplicitModels>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, SecondaryIndexes extends Record<string, any> = ModelSecondaryIndexes<SchemaTypes<Schema>>> = ResolvedFields & CustomOperationHandlerTypes<ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>['customOperations']> & ResolvedFields & { | ||
[__modelMeta__]: IdentifierMeta & ImplicitModelsIdentifierMeta & SecondaryIndexes & RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> & NonModelTypes & ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>; | ||
}; | ||
export {}; |
@@ -7,2 +7,3 @@ import type { ModelSchema } from '../ModelSchema'; | ||
import type { ResolveRefsOfCustomType, ResolveRefValueArrayTraits } from './ResolveFieldProperties'; | ||
import type { AppSyncResolverHandler } from 'aws-lambda'; | ||
/** | ||
@@ -48,1 +49,76 @@ * Creates meta types for custom operations from a schema. | ||
export type ResolveRef<Shape extends RefTypeParamShape, FullyResolvedSchema extends Record<string, unknown>, NonModelTypes extends NonModelTypesShape, Link = Shape['link'], RefValue = Link extends keyof FullyResolvedSchema ? FullyResolvedSchema[Link] : Link extends keyof NonModelTypes['enums'] ? NonModelTypes['enums'][Link] : Link extends keyof NonModelTypes['customTypes'] ? ResolveRefsOfCustomType<NonModelTypes, NonModelTypes['customTypes'][Link]> : never, Value = Shape['valueRequired'] extends true ? RefValue : RefValue | null> = ResolveRefValueArrayTraits<Shape, Value>; | ||
/** | ||
* The kind of shape we need to map to custom handler (e.g., lambda) function | ||
* signatures. | ||
*/ | ||
type CustomOperationsMap = Record<string, CustomOperationMinimalDef>; | ||
/** | ||
* The minimal amount of structure needed to extract types for a custom handler. | ||
*/ | ||
type CustomOperationMinimalDef = { | ||
arguments: any; | ||
returnType: any; | ||
}; | ||
/** | ||
* Derives the signature and types for a lambda handler for a particular | ||
* custom Query or Mutation from a Schema. | ||
*/ | ||
type IndvidualCustomHandlerTypes<Op extends CustomOperationMinimalDef> = { | ||
/** | ||
* Handler type for lambda function implementations. E.g., | ||
* | ||
* ```typescript | ||
* import type { Schema } from './resource'; | ||
* | ||
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => { | ||
* // event and context will be fully typed inside here. | ||
* } | ||
* ``` | ||
*/ | ||
functionHandler: AppSyncResolverHandler<Op['arguments'], LambdaReturnType<Op['returnType']>>; | ||
/** | ||
* The `context.arguments` type for lambda function implementations. | ||
* | ||
* ```typescript | ||
* import type { Schema } from './resource'; | ||
* | ||
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => { | ||
* // Provides this type, if needed: | ||
* const args: Schema['echo']['functionHandlerArguments'] = event.arguments; | ||
* } | ||
* ``` | ||
*/ | ||
functionHandlerArguments: Op['arguments']; | ||
/** | ||
* The return type expected by a lambda function handler. | ||
* | ||
* ```typescript | ||
* import type { Schema } from './resource'; | ||
* | ||
* export const handler: Schema['echo']['functionHandler'] = async (event, context) => { | ||
* // Result type enforced here: | ||
* const result: Schema['echo']['functionHandlerResult'] = buildResult(...); | ||
* | ||
* // `Result` type matches expected function return type here: | ||
* return result; | ||
* } | ||
* ``` | ||
*/ | ||
functionHandlerResult: LambdaReturnType<Op['returnType']>; | ||
}; | ||
/** | ||
* Derives the function signatures for a lambda handlers for all the provided | ||
* custom queries and mutations. | ||
*/ | ||
export type CustomOperationHandlerTypes<CustomOperations extends CustomOperationsMap> = { | ||
[K in keyof CustomOperations]: IndvidualCustomHandlerTypes<CustomOperations[K]>; | ||
}; | ||
/** | ||
* Returns a return type with lazy loaders removed. | ||
* | ||
* (Custom handlers should not return lazy loaded fields -- they're *lazy loaded*.) | ||
*/ | ||
type LambdaReturnType<T> = T extends Record<string, any> ? { | ||
[K in keyof Exclude<T, null | undefined> as Exclude<T, null | undefined>[K] extends (...args: any) => any ? never : K]: Exclude<T, null | undefined>[K]; | ||
} : T | (null extends T ? null : never) | (undefined extends T ? undefined : never); | ||
export {}; |
@@ -275,2 +275,23 @@ "use strict"; | ||
/** | ||
* Validate that no implicit fields are used by the model definition | ||
* | ||
* @param existing An existing field map | ||
* @param implicitFields A field map inferred from other schema usage | ||
* | ||
* @throws An error when an undefined field is used or when a field is used in a way that conflicts with its generated definition | ||
*/ | ||
function validateStaticFields(existing, implicitFields) { | ||
if (implicitFields === undefined) { | ||
return; | ||
} | ||
for (const [k, field] of Object.entries(implicitFields)) { | ||
if (!existing[k]) { | ||
throw new Error(`Field ${k} isn't defined.`); | ||
} | ||
else if (areConflicting(existing[k], field)) { | ||
throw new Error(`Field ${k} defined twice with conflicting definitions.`); | ||
} | ||
} | ||
} | ||
/** | ||
* Produces a new field definition object from every field definition object | ||
@@ -725,2 +746,3 @@ * given as an argument. Performs validation (conflict detection) as objects | ||
: 'sql'; | ||
const staticSchema = schema.data.configuration.database.engine === 'dynamodb' ? false : true; | ||
const fkFields = allImpliedFKs(schema); | ||
@@ -777,2 +799,19 @@ const topLevelTypes = Object.entries(schema.data.types); | ||
} | ||
else if (staticSchema) { | ||
const fields = { ...typeDef.data.fields }; | ||
const identifier = typeDef.data.identifier; | ||
const [partitionKey] = identifier; | ||
validateStaticFields(fields, fkFields[typeName]); | ||
const { authString, authFields } = calculateAuth(mostRelevantAuthRules); | ||
if (authString == '') { | ||
throw new Error(`Model \`${typeName}\` is missing authorization rules. Add global rules to the schema or ensure every model has its own rules.`); | ||
} | ||
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields); | ||
validateStaticFields(fields, authFields); | ||
const { gqlFields, models } = processFields(typeName, fields, fieldLevelAuthRules, identifier, partitionKey); | ||
topLevelTypes.push(...models); | ||
const joined = gqlFields.join('\n '); | ||
const model = `type ${typeName} @model ${authString}\n{\n ${joined}\n}`; | ||
gqlModels.push(model); | ||
} | ||
else { | ||
@@ -779,0 +818,0 @@ const fields = mergeFieldObjects(typeDef.data.fields, fkFields[typeName]); |
{ | ||
"name": "@aws-amplify/data-schema", | ||
"version": "0.13.15", | ||
"version": "0.13.16", | ||
"license": "Apache-2.0", | ||
@@ -20,3 +20,4 @@ "repository": { | ||
"types": "./lib-esm/index.d.ts", | ||
"import": "./lib-esm/index.js" | ||
"import": "./lib-esm/index.js", | ||
"node": "./index.ts" | ||
}, | ||
@@ -36,3 +37,4 @@ "./internals": { | ||
"dependencies": { | ||
"@aws-amplify/data-schema-types": "*" | ||
"@aws-amplify/data-schema-types": "*", | ||
"@types/aws-lambda": "^8.10.134" | ||
}, | ||
@@ -39,0 +41,0 @@ "devDependencies": { |
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
639240
3824
2
+ Added@types/aws-lambda@^8.10.134
+ Added@types/aws-lambda@8.10.146(transitive)