Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-amplify/data-schema

Package Overview
Dependencies
Maintainers
10
Versions
176
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-amplify/data-schema - npm Package Compare versions

Comparing version 0.13.16 to 0.13.17

21

lib-esm/src/ClientSchema.d.ts
import { type __modelMeta__ } from '@aws-amplify/data-schema-types';
import type { ModelSchema } from './ModelSchema';
import { type GenericModelSchema, type RDSModelSchema } from './ModelSchema';
import type { ResolveSchema, SchemaTypes } from './MappedTypes/ResolveSchema';
import type { CreateImplicitModelsFromRelations, ResolveFieldProperties } from './MappedTypes/ResolveFieldProperties';
import type { CreateImplicitModelsFromRelations, ResolveFieldProperties, ResolveStaticFieldProperties } from './MappedTypes/ResolveFieldProperties';
import type { ModelIdentifier, ModelSecondaryIndexes, RelationalMetadata } from './MappedTypes/ModelMetadata';
import type { ExtractNonModelTypes, NonModelTypesShape } from './MappedTypes/ExtractNonModelTypes';
import { ResolveCustomOperations, CustomOperationHandlerTypes } from './MappedTypes/CustomOperations';
export type ClientSchema<Schema extends ModelSchema<any, any>> = InternalClientSchema<Schema>;
export type ClientSchema<Schema extends GenericModelSchema<any>> = InternalClientSchema<Schema>;
/**
* Types for unwrapping generic type args into client-consumable types
*
* @typeParam Schema - Type Beast schema type
* @typeParam Schema - Data schema builder model type
*

@@ -18,18 +18,13 @@ * The following params are used solely as variables in order to simplify mapped type usage.

* @internal @typeParam NonModelTypes - Custom Types, Enums, and Custom Operations
* @internal @typeParam ResolvedSchema - Schema/Models/Fields structure with generic type args extracted
* @internal @typeParam ResolvedFields - Resovled client-facing types used for CRUDL response shapes
* @internal @typeParam IdentifierMeta - Map of model primary index metadata
* @internal @typeParam ImplicitModels - The implicit models created to represent relationships
* @internal @typeParam ResolvedFields - Resolved client-facing types used for CRUDL response shapes
* @internal @typeParam SecondaryIndexes - Map of model secondary index metadata
*
* @internal @typeParam Meta - Stores schema metadata: identifier, relationship metadata;
* used by `API.generateClient` to craft strongly typed mutation inputs; hidden from customer-facing types behind __modelMeta__ symbol
*
*/
type InternalClientSchema<Schema extends ModelSchema<any, any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>, ImplicitModels = CreateImplicitModelsFromRelations<ResolvedSchema>, ImplicitModelsIdentifierMeta = {
type InternalClientSchema<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>, ImplicitModels = Schema extends RDSModelSchema<any, any> ? object : CreateImplicitModelsFromRelations<ResolvedSchema>, ImplicitModelsIdentifierMeta = {
[ImplicitModel in keyof ImplicitModels]: {
identifier: 'id';
};
}, 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 & {
}, ResolvedFields extends Record<string, unknown> = Schema extends RDSModelSchema<any, any> ? ResolveStaticFieldProperties<Schema, NonModelTypes, object> : ResolveFieldProperties<Schema, NonModelTypes, ImplicitModels>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, SecondaryIndexes extends Record<string, any> = Schema extends RDSModelSchema<any, any> ? object : ModelSecondaryIndexes<SchemaTypes<Schema>>> = CustomOperationHandlerTypes<ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>['customOperations']> & ResolvedFields & {
[__modelMeta__]: IdentifierMeta & ImplicitModelsIdentifierMeta & SecondaryIndexes & RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> & NonModelTypes & ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>;
};
export {};

@@ -1,2 +0,2 @@

import type { ModelSchema } from '../ModelSchema';
import type { GenericModelSchema } from '../ModelSchema';
import type { NonModelTypesShape } from './ExtractNonModelTypes';

@@ -11,3 +11,3 @@ import type { CustomOperation, CustomOperationParamShape } from '../CustomOperation';

*/
export type ResolveCustomOperations<Schema extends ModelSchema<any, any>, FullyResolvedSchema extends Record<string, unknown>, NonModelTypes extends NonModelTypesShape> = {
export type ResolveCustomOperations<Schema extends GenericModelSchema<any>, FullyResolvedSchema extends Record<string, unknown>, NonModelTypes extends NonModelTypesShape> = {
customOperations: {

@@ -26,3 +26,3 @@ [OpName in keyof CustomOpShapes<Schema>]: {

*/
export type CustomOpShapes<Schema extends ModelSchema<any, any>> = {
export type CustomOpShapes<Schema extends GenericModelSchema<any>> = {
[K in keyof Schema['data']['types'] as Schema['data']['types'][K] extends CustomOperation<any, any> ? K : never]: Schema['data']['types'][K] extends CustomOperation<infer Shape, any> ? Shape : never;

@@ -29,0 +29,0 @@ };

@@ -5,3 +5,3 @@ import type { UnionToIntersection, LazyLoader, ExcludeEmpty } from '@aws-amplify/data-schema-types';

import type { ModelType, ModelTypeParamShape } from '../ModelType';
import type { ModelSchema } from '../ModelSchema';
import type { GenericModelSchema } from '../ModelSchema';
import type { ModelRelationalField, ModelRelationalFieldParamShape, ModelRelationalTypeArgFactory, ModelRelationshipTypes } from '../ModelRelationalField';

@@ -17,5 +17,6 @@ import type { AllImpliedFKs } from './ForeignKeys';

import type { CustomOperation, CustomOperationParamShape } from '../CustomOperation';
export type ResolveFieldProperties<Schema extends ModelSchema<any, any>, NonModelTypes extends NonModelTypesShape, ImplicitModelsSchema, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, {
export type ResolveFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ImplicitModelsSchema, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, {
identifier: string;
}> = ModelIdentifier<SchemaTypes<Schema>>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema & ImplicitModelsSchema, IdentifierMeta>, FieldsWithRelationships = ResolveRelationships<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<MarkModelsNonNullableFieldsRequired<FieldsWithRelationships>>, FilterFieldTypes<MarkModelsNullableFieldsOptional<FieldsWithRelationships>>, FilterFieldTypes<ModelImpliedAuthFields<Schema>>, AllImpliedFKs<ResolvedSchema, IdentifierMeta>>;
export type ResolveStaticFieldProperties<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape, ImplicitModelsSchema, ResolvedSchema = ResolveSchema<Schema>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<ResolvedSchema & ImplicitModelsSchema, object>, FieldsWithRelationships = ResolveRelationships<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<MarkModelsNonNullableFieldsRequired<FieldsWithRelationships>>, FilterFieldTypes<MarkModelsNullableFieldsOptional<FieldsWithRelationships>>>;
export type CreateImplicitModelsFromRelations<Schema> = UnionToIntersection<ExcludeEmpty<{

@@ -64,7 +65,7 @@ [ModelProp in keyof Schema]: {

} : never;
export type ModelImpliedAuthFields<Schema extends ModelSchema<any, any>> = {
export type ModelImpliedAuthFields<Schema extends GenericModelSchema<any>> = {
[ModelKey in keyof Schema['data']['types'] as Schema['data']['types'][ModelKey] extends EnumType<EnumTypeParamShape> ? never : Schema['data']['types'][ModelKey] extends CustomType<CustomTypeParamShape> ? never : Schema['data']['types'][ModelKey] extends CustomOperation<CustomOperationParamShape, any> ? never : ModelKey]: Schema['data']['types'][ModelKey] extends ModelType<infer Model, any> ? AllAuthFieldsForModel<Schema, Model> : object;
};
type AllAuthFieldsForModel<Schema extends ModelSchema<any, any>, Model extends Schema['data']['types'][keyof Schema['data']['types']]> = (Model['authorization'][number] extends never ? Schema['data']['authorization'][number] extends never ? object : ImpliedAuthFields<Schema['data']['authorization'][number]> : ImpliedAuthFields<Model['authorization'][number]>) & ImpliedAuthFieldsFromFields<Model>;
type AllAuthFieldsForModel<Schema extends GenericModelSchema<any>, Model extends Schema['data']['types'][keyof Schema['data']['types']]> = (Model['authorization'][number] extends never ? Schema['data']['authorization'][number] extends never ? object : ImpliedAuthFields<Schema['data']['authorization'][number]> : ImpliedAuthFields<Model['authorization'][number]>) & ImpliedAuthFieldsFromFields<Model>;
type ImpliedAuthFieldsFromFields<T> = UnionToIntersection<T extends ModelTypeParamShape ? T['fields'][keyof T['fields']] extends ModelField<any, any, infer Auth> | ModelRelationalField<any, any, any, infer Auth> | RefType<any, any, infer Auth> ? Auth extends Authorization<any, any, any> ? ImpliedAuthFields<Auth> : object : object : object>;
export {};
import type { ModelType } from '../ModelType';
import type { ModelSchema } from '../ModelSchema';
import type { GenericModelSchema } from '../ModelSchema';
import type { ModelRelationalField, ModelRelationshipTypes, RelationTypeFunctionOmitMapping } from '../ModelRelationalField';

@@ -10,3 +10,3 @@ import type { ModelField } from '../ModelField';

export type ResolveSchema<Schema> = FieldTypes<ModelTypes<SchemaTypes<Schema>>>;
export type SchemaTypes<T> = T extends ModelSchema<any, any> ? T['data']['types'] : never;
export type SchemaTypes<T> = T extends GenericModelSchema<any> ? T['data']['types'] : never;
/**

@@ -13,0 +13,0 @@ * Resolves model types

@@ -7,2 +7,8 @@ import type { DerivedApiDefinition, SetTypeSubArg } from '@aws-amplify/data-schema-types';

import { SchemaAuthorization } from './Authorization';
import { Brand } from './util';
export declare const rdsSchemaBrandName = "RDSSchema";
export declare const rdsSchemaBrand: Brand<"RDSSchema">;
export type RDSSchemaBrand = Brand<typeof rdsSchemaBrandName>;
export declare const ddbSchemaBrandName = "DDBSchema";
export type DDBSchemaBrand = Brand<typeof ddbSchemaBrandName>;
type SchemaContent = ModelType<ModelTypeParamShape, any> | CustomType<CustomTypeParamShape> | EnumType<EnumTypeParamShape> | CustomOperation<CustomOperationParamShape, any>;

@@ -42,3 +48,3 @@ type ModelSchemaContents = Record<string, SchemaContent>;

};
export type SQLModelSchemaParamShape = ModelSchemaParamShape & {
export type RDSModelSchemaParamShape = ModelSchemaParamShape & {
setSqlStatementFolderPath?: string;

@@ -53,5 +59,3 @@ };

};
export type ModelSchema<T extends ModelSchemaParamShape, UsedMethods extends 'authorization' = never> = Omit<{
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(auth: AuthRules[]) => ModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
}, UsedMethods> & {
type BaseSchema<T extends ModelSchemaParamShape> = {
data: T;

@@ -63,9 +67,14 @@ models: {

};
type SQLModelSchemaFunctions = 'setSqlStatementFolderPath' | 'addQueries' | 'addMutations' | 'addSubscriptions';
export type SQLModelSchema<T extends SQLModelSchemaParamShape, UsedMethods extends 'authorization' | SQLModelSchemaFunctions = never> = ModelSchema<T, Exclude<UsedMethods, SQLModelSchemaFunctions>> & Omit<{
setSqlStatementFolderPath: (path: string) => SQLModelSchema<T, UsedMethods | 'setSqlStatementFolderPath'>;
addQueries: (types: Record<string, QueryCustomOperation>) => SQLModelSchema<T, UsedMethods | 'addQueries'>;
addMutations: (types: Record<string, MutationCustomOperation>) => SQLModelSchema<T, UsedMethods | 'addMutations'>;
addSubscriptions: (types: Record<string, SubscriptionCustomOperation>) => SQLModelSchema<T, UsedMethods | 'addSubscriptions'>;
}, UsedMethods>;
export type GenericModelSchema<T extends ModelSchemaParamShape> = BaseSchema<T> & Brand<string>;
export type ModelSchema<T extends ModelSchemaParamShape, UsedMethods extends 'authorization' = never> = Omit<{
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(auth: AuthRules[]) => ModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'>;
}, UsedMethods> & BaseSchema<T> & DDBSchemaBrand;
type RDSModelSchemaFunctions = 'setSqlStatementFolderPath' | 'addQueries' | 'addMutations' | 'addSubscriptions' | 'authorization';
export type RDSModelSchema<T extends RDSModelSchemaParamShape, UsedMethods extends RDSModelSchemaFunctions = never> = Omit<{
setSqlStatementFolderPath: (path: string) => RDSModelSchema<T, UsedMethods | 'setSqlStatementFolderPath'>;
addQueries: (types: Record<string, QueryCustomOperation>) => RDSModelSchema<T, UsedMethods | 'addQueries'>;
addMutations: (types: Record<string, MutationCustomOperation>) => RDSModelSchema<T, UsedMethods | 'addMutations'>;
addSubscriptions: (types: Record<string, SubscriptionCustomOperation>) => RDSModelSchema<T, UsedMethods | 'addSubscriptions'>;
authorization: <AuthRules extends SchemaAuthorization<any, any, any>>(auth: AuthRules[]) => RDSModelSchema<SetTypeSubArg<T, 'authorization', AuthRules[]>, UsedMethods | 'authorization'> & RDSSchemaBrand;
}, UsedMethods> & BaseSchema<T> & RDSSchemaBrand;
/**

@@ -85,3 +94,3 @@ * Amplify API Next Model Schema shape

configuration: any;
}> : SQLModelSchema<{
}> : RDSModelSchema<{
types: Types;

@@ -88,0 +97,0 @@ authorization: [];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.configure = exports.schema = exports.isModelSchema = void 0;
exports.configure = exports.schema = exports.isModelSchema = exports.ddbSchemaBrandName = exports.rdsSchemaBrand = exports.rdsSchemaBrandName = void 0;
const ModelType_1 = require("./ModelType");
const SchemaProcessor_1 = require("./SchemaProcessor");
const util_1 = require("./util");
exports.rdsSchemaBrandName = 'RDSSchema';
exports.rdsSchemaBrand = (0, util_1.brand)(exports.rdsSchemaBrandName);
exports.ddbSchemaBrandName = 'DDBSchema';
const ddbSchemaBrand = (0, util_1.brand)(exports.ddbSchemaBrandName);
/**

@@ -32,5 +37,19 @@ * Filter the schema types down to only include the ModelTypes as SchemaModelType

exports.isModelSchema = isModelSchema;
function _sqlSchemaExtension(schema) {
function _rdsSchema(types, config) {
const data = {
types,
authorization: [],
configuration: config,
};
return {
...schema,
data,
transform() {
const internalSchema = { data };
return (0, SchemaProcessor_1.processSchema)({ schema: internalSchema });
},
authorization(rules) {
this.data.authorization = rules;
const { authorization: _, ...rest } = this;
return rest;
},
setSqlStatementFolderPath(path) {

@@ -56,5 +75,6 @@ this.data.setSqlStatementFolderPath = path;

},
...exports.rdsSchemaBrand,
};
}
function _baseSchema(types, config) {
function _ddbSchema(types, config) {
const data = {

@@ -77,2 +97,3 @@ types,

models: filterSchemaModelTypes(data.types),
...ddbSchemaBrand,
};

@@ -83,4 +104,4 @@ }

return (config.database.engine === 'dynamodb'
? _baseSchema(types, config)
: _sqlSchemaExtension(_baseSchema(types, config)));
? _ddbSchema(types, config)
: _rdsSchema(types, config));
};

@@ -87,0 +108,0 @@ }

{
"name": "@aws-amplify/data-schema",
"version": "0.13.16",
"version": "0.13.17",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc