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
172
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.12.1 to 0.12.2

40

lib-esm/src/Authorization.d.ts

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

export type Operation = (typeof Operations)[number];
export type Authorization<AuthField extends string | undefined, AuthFieldPlurality extends boolean> = {
export type Authorization<AuthStrategy extends Strategy, AuthField extends string | undefined, AuthFieldPlurality extends boolean> = {
[__data]: {
strategy?: Strategy;
strategy?: AuthStrategy;
provider?: Provider;

@@ -61,4 +61,4 @@ operations?: Operation[];

};
declare function to<SELF extends Authorization<any, any>>(this: SELF, operations: Operation[]): Omit<SELF, "to">;
declare function inField<SELF extends Authorization<any, any>, Field extends string>(this: SELF, field: Field): BuilderMethods<Omit<SELF, "inField">> & Authorization<Field, SELF[typeof __data]["multiOwner"]>;
declare function to<SELF extends Authorization<any, any, any>>(this: SELF, operations: Operation[]): Omit<SELF, "to">;
declare function inField<SELF extends Authorization<any, any, any>, Field extends string>(this: SELF, field: Field): BuilderMethods<Omit<SELF, "inField">> & Authorization<SELF[typeof __data]["strategy"], Field, SELF[typeof __data]["multiOwner"]>;
/**

@@ -72,4 +72,4 @@ * Specifies a property of the identity JWT to use in place of `sub::username`

*/
declare function identityClaim<SELF extends Authorization<any, any>>(this: SELF, property: string): Omit<SELF, "identityClaim">;
declare function withClaimIn<SELF extends Authorization<any, any>>(this: SELF, property: string): Omit<SELF, "withClaimIn">;
declare function identityClaim<SELF extends Authorization<any, any, any>>(this: SELF, property: string): Omit<SELF, "identityClaim">;
declare function withClaimIn<SELF extends Authorization<any, any, any>>(this: SELF, property: string): Omit<SELF, "withClaimIn">;
/**

@@ -87,3 +87,3 @@ * Defines an authorization rule for your data models and fields. First choose an authorization strategy (`public`,

*/
readonly public: (provider?: PublicProvider) => Authorization<"owner", false> & {
readonly public: (provider?: PublicProvider) => Authorization<"public", undefined, false> & {
to: typeof to;

@@ -97,3 +97,3 @@ };

*/
readonly private: (provider?: PrivateProvider) => Authorization<"owner", false> & {
readonly private: (provider?: PrivateProvider) => Authorization<"private", undefined, false> & {
to: typeof to;

@@ -116,3 +116,3 @@ };

*/
readonly owner: (provider?: OwnerProviders) => Authorization<"owner", false> & {
readonly owner: (provider?: OwnerProviders) => Authorization<"owner", "owner", false> & {
to: typeof to;

@@ -137,3 +137,3 @@ inField: typeof inField;

*/
readonly multipleOwners: (provider?: OwnerProviders) => Authorization<"owner", true> & {
readonly multipleOwners: (provider?: OwnerProviders) => Authorization<"owner", "owner", true> & {
to: typeof to;

@@ -155,3 +155,3 @@ inField: typeof inField;

*/
readonly specificGroup: (group: string, provider?: GroupProvider) => Authorization<"owner", false> & {
readonly specificGroup: (group: string, provider?: GroupProvider) => Authorization<"groups", undefined, false> & {
to: typeof to;

@@ -172,3 +172,3 @@ withClaimIn: typeof withClaimIn;

*/
readonly specificGroups: (groups: string[], provider?: GroupProvider) => Authorization<"owner", false> & {
readonly specificGroups: (groups: string[], provider?: GroupProvider) => Authorization<"groups", undefined, false> & {
to: typeof to;

@@ -189,3 +189,3 @@ withClaimIn: typeof withClaimIn;

*/
readonly groupDefinedIn: <T extends string>(groupsField: T, provider?: GroupProvider) => Authorization<T, false> & {
readonly groupDefinedIn: <T extends string>(groupsField: T, provider?: GroupProvider) => Authorization<"groups", T, false> & {
to: typeof to;

@@ -205,6 +205,6 @@ };

*/
readonly groupsDefinedIn: <T_1 extends string>(groupsField: T_1, provider?: GroupProvider) => Authorization<T_1, true> & {
readonly groupsDefinedIn: <T_1 extends string>(groupsField: T_1, provider?: GroupProvider) => Authorization<"groups", T_1, true> & {
to: typeof to;
};
readonly custom: (provider?: CustomProvider) => Authorization<"owner", false> & {
readonly custom: (provider?: CustomProvider) => Authorization<"custom", undefined, false> & {
to: typeof to;

@@ -236,7 +236,7 @@ };

*/
export type ImpliedAuthField<T extends Authorization<any, any>> = T extends Authorization<infer Field, infer isMulti> ? Field extends string ? isMulti extends true ? {
export type ImpliedAuthField<T extends Authorization<any, any, any>> = T extends Authorization<infer _Strat, infer Field, infer isMulti> ? Field extends undefined ? never : Field extends string ? isMulti extends true ? {
[K in Field]?: string[];
} : {
[K in Field]?: string;
} : object : object;
} : never : never;
/**

@@ -263,5 +263,5 @@ * Turns the type from a list of `Authorization` rules like this:

*/
export type ImpliedAuthFields<T extends Authorization<any, any>> = UnionToIntersection<ImpliedAuthField<T>>;
export declare const accessData: <T extends Authorization<any, any>>(authorization: T) => {
strategy?: "public" | "private" | "owner" | "groups" | "custom" | undefined;
export type ImpliedAuthFields<T extends Authorization<any, any, any>> = ImpliedAuthField<T> extends never ? never : UnionToIntersection<ImpliedAuthField<T>>;
export declare const accessData: <T extends Authorization<any, any, any>>(authorization: T) => {
strategy?: any;
provider?: "function" | "apiKey" | "iam" | "userPools" | "oidc" | undefined;

@@ -268,0 +268,0 @@ operations?: ("create" | "update" | "delete" | "read" | "get" | "list" | "sync" | "listen" | "search")[] | undefined;

@@ -113,6 +113,2 @@ "use strict";

...defaults,
// might not even be needed ...
// dependencies: {
// owner: {},
// },
},

@@ -119,0 +115,0 @@ ...builderMethods,

@@ -7,3 +7,3 @@ import { type Prettify, __modelMeta__ } from '@aws-amplify/data-schema-types';

import type { ExtractNonModelTypes, NonModelTypesShape } from './MappedTypes/ExtractNonModelTypes';
export type ClientSchema<Schema extends ModelSchema<any>> = InternalClientSchema<Schema>;
export type ClientSchema<Schema extends ModelSchema<any, any>> = InternalClientSchema<Schema>;
/**

@@ -25,5 +25,5 @@ * Types for unwrapping generic type args into client-consumable types

*/
type InternalClientSchema<Schema extends ModelSchema<any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, ResolvedFields extends Record<string, unknown> = ResolveFieldProperties<Schema, NonModelTypes>, RelationshipMeta = RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta>, Meta = IdentifierMeta & RelationshipMeta & NonModelTypes> = Prettify<ResolvedFields & {
type InternalClientSchema<Schema extends ModelSchema<any, any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, ResolvedFields extends Record<string, unknown> = ResolveFieldProperties<Schema, NonModelTypes>, RelationshipMeta = RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta>, Meta = IdentifierMeta & RelationshipMeta & NonModelTypes> = Prettify<ResolvedFields & {
[__modelMeta__]: Meta;
}>;
export {};

@@ -7,3 +7,3 @@ import { Brand, SetTypeSubArg } from '@aws-amplify/data-schema-types';

type CustomReturnType = RefType<any>;
type InternalCustomFields = Record<string, InternalField>;
type CustomFunctionRefType = string;
type InternalCustomArguments = Record<string, InternalField>;

@@ -16,10 +16,11 @@ type InternalCustomReturnType = InternalRef;

returnType: CustomReturnType | null;
authorization: Authorization<any, any>[];
functionRef: string | null;
authorization: Authorization<any, any, any>[];
typeName: CustomOperationName;
};
type InternalCustomData = CustomData & {
fields: InternalCustomFields;
arguments: InternalCustomArguments;
returnType: InternalCustomReturnType;
authorization: Authorization<any, any>[];
functionRef: string | null;
authorization: Authorization<any, any, any>[];
};

@@ -29,3 +30,4 @@ export type CustomOperationParamShape = {

returnType: CustomReturnType | null;
authorization: Authorization<any, any>[];
functionRef: string | null;
authorization: Authorization<any, any, any>[];
typeName: CustomOperationName;

@@ -36,3 +38,4 @@ };

returns<ReturnType extends CustomReturnType>(returnType: ReturnType): CustomOperation<SetTypeSubArg<T, 'returnType', ReturnType>, K | 'returns'>;
authorization<AuthRuleType extends Authorization<any, any>>(rules: AuthRuleType[]): CustomOperation<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization'>;
function<FunctionRef extends CustomFunctionRefType>(functionRefOrName: FunctionRef): CustomOperation<SetTypeSubArg<T, 'functionRef', FunctionRef>, K | 'function'>;
authorization<AuthRuleType extends Authorization<any, any, any>>(rules: AuthRuleType[]): CustomOperation<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization'>;
}, K>, 'customOperation'>;

@@ -49,2 +52,3 @@ /**

returnType: null;
functionRef: null;
authorization: [];

@@ -56,2 +60,3 @@ typeName: 'Query';

returnType: null;
functionRef: null;
authorization: [];

@@ -63,2 +68,3 @@ typeName: 'Mutation';

returnType: null;
functionRef: null;
authorization: [];

@@ -65,0 +71,0 @@ typeName: 'Subscription';

@@ -16,2 +16,3 @@ "use strict";

returnType: null,
functionRef: null,
authorization: [],

@@ -29,2 +30,6 @@ typeName: typeName,

},
function(functionRefOrName) {
data.functionRef = functionRefOrName;
return this;
},
authorization(rules) {

@@ -31,0 +36,0 @@ data.authorization = rules;

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

import type { EnumType, EnumTypeParamShape } from '../EnumType';
export type ResolveFieldProperties<Schema extends ModelSchema<any>, NonModelTypes extends NonModelTypesShape, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, {
export type ResolveFieldProperties<Schema extends ModelSchema<any, any>, NonModelTypes extends NonModelTypesShape, ResolvedSchema = ResolveSchema<Schema>, IdentifierMeta extends Record<string, {
identifier: string;

@@ -55,6 +55,7 @@ }> = ModelIdentifier<SchemaTypes<Schema>>, FieldsWithInjectedModels = InjectImplicitModels<ResolvedSchema>, FieldsWithInjectedImplicitFields = InjectImplicitModelFields<FieldsWithInjectedModels, IdentifierMeta>, FieldsWithRelationships = ResolveRelationships<FieldsWithInjectedImplicitFields, NonModelTypes>> = Intersection<FilterFieldTypes<RequiredFieldTypes<FieldsWithRelationships>>, FilterFieldTypes<OptionalFieldTypes<FieldsWithRelationships>>, FilterFieldTypes<ModelImpliedAuthFields<Schema>>, AllImpliedFKs<ResolvedSchema, IdentifierMeta>>;

} : never;
export type ModelImpliedAuthFields<Schema extends ModelSchema<any>> = {
[ModelKey in keyof Schema['data']['types'] as Schema['data']['types'][ModelKey] extends EnumType<EnumTypeParamShape> ? never : Schema['data']['types'][ModelKey] extends CustomType<CustomTypeParamShape> ? never : ModelKey]: Schema['data']['types'][ModelKey] extends ModelType<infer Model, any> ? ImpliedAuthFields<Model['authorization'][number]> & ImpliedAuthFieldsFromFields<Model> : object;
export type ModelImpliedAuthFields<Schema extends ModelSchema<any, any>> = {
[ModelKey in keyof Schema['data']['types'] as Schema['data']['types'][ModelKey] extends EnumType<EnumTypeParamShape> ? never : Schema['data']['types'][ModelKey] extends CustomType<CustomTypeParamShape> ? never : ModelKey]: Schema['data']['types'][ModelKey] extends ModelType<infer Model, any> ? AllAuthFieldsForModel<Schema, Model> : object;
};
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> ? ImpliedAuthFields<Auth> : object : object : 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 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 {};

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

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

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

@@ -35,3 +35,3 @@ import { Authorization } from './Authorization';

default: undefined | ModelFieldTypeParamOuter;
authorization: Authorization<any, any>[];
authorization: Authorization<any, any, any>[];
};

@@ -72,3 +72,3 @@ type ModelFieldTypeParamInner = string | number | boolean | Date | Json | null;

*/
authorization<AuthRuleType extends Authorization<any, any>>(rules: AuthRuleType[]): ModelField<T, K | 'authorization', AuthRuleType>;
authorization<AuthRuleType extends Authorization<any, any, any>>(rules: AuthRuleType[]): ModelField<T, K | 'authorization', AuthRuleType>;
}, K> & {

@@ -75,0 +75,0 @@ [__auth]?: Auth;

@@ -22,3 +22,3 @@ import { SetTypeSubArg } from '@aws-amplify/data-schema-types';

relationName?: string;
authorization: Authorization<any, any>[];
authorization: Authorization<any, any, any>[];
};

@@ -51,3 +51,3 @@ export type ModelRelationalFieldParamShape = {

*/
authorization<AuthRuleType extends Authorization<any, any>>(rules: AuthRuleType[]): ModelRelationalField<T, K | 'authorization', K, AuthRuleType>;
authorization<AuthRuleType extends Authorization<any, any, any>>(rules: AuthRuleType[]): ModelRelationalField<T, K | 'authorization', K, AuthRuleType>;
}, K> & {

@@ -54,0 +54,0 @@ [__auth]?: Auth;

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

import type { DerivedApiDefinition } from '@aws-amplify/data-schema-types';
import type { DerivedApiDefinition, SetTypeSubArg } from '@aws-amplify/data-schema-types';
import type { ModelType, ModelTypeParamShape, InternalModel } from './ModelType';

@@ -7,2 +7,3 @@ import type { EnumType } from './EnumType';

export { __auth } from './ModelField';
import { Authorization } from './Authorization';
type ModelSchemaModels = Record<string, ModelType<ModelTypeParamShape, any>>;

@@ -12,2 +13,3 @@ type InternalSchemaModels = Record<string, InternalModel | EnumType<any> | CustomType<any> | InternalCustom>;

types: ModelSchemaModels;
authorization: Authorization<any, any, any>[];
};

@@ -17,5 +19,8 @@ export type InternalSchema = {

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

@@ -43,2 +48,3 @@ transform: () => DerivedApiDefinition;

types: Types;
authorization: [];
}>;

@@ -17,3 +17,3 @@ "use strict";

function _schema(types) {
const data = { types };
const data = { types, authorization: [] };
const transform = () => {

@@ -23,3 +23,7 @@ const internalSchema = { data };

};
return { data, transform };
const authorization = (rules) => {
data.authorization = rules;
return { data, transform };
};
return { data, transform, authorization };
}

@@ -26,0 +30,0 @@ /**

@@ -11,3 +11,3 @@ import type { SetTypeSubArg } from '@aws-amplify/data-schema-types';

identifier: string[];
authorization: Authorization<any, any>[];
authorization: Authorization<any, any, any>[];
};

@@ -17,3 +17,3 @@ type InternalModelData = ModelData & {

identifier: string[];
authorization: Authorization<any, any>[];
authorization: Authorization<any, any, any>[];
};

@@ -23,3 +23,3 @@ export type ModelTypeParamShape = {

identifier: string[];
authorization: Authorization<any, any>[];
authorization: Authorization<any, any, any>[];
};

@@ -60,3 +60,3 @@ type ExtractType<T extends ModelTypeParamShape> = {

type ConflictingAuthRulesMap<T extends ModelTypeParamShape> = {
[K in keyof ExtractType<T>]: K extends string ? string extends ExtractType<T>[K] ? Authorization<K, true> : string[] extends ExtractType<T>[K] ? Authorization<K, false> : Authorization<K, true> | Authorization<K, false> : never;
[K in keyof ExtractType<T>]: K extends string ? string extends ExtractType<T>[K] ? Authorization<any, K, true> : string[] extends ExtractType<T>[K] ? Authorization<any, K, false> : Authorization<any, K, true> | Authorization<any, K, false> : never;
};

@@ -90,3 +90,3 @@ /**

identifier<ID extends IdentifierType<T> = []>(identifier: ID): ModelType<SetTypeSubArg<T, 'identifier', ID>, K | 'identifier'>;
authorization<AuthRuleType extends Authorization<any, any>>(rules: Exclude<AuthRuleType, ConflictingAuthRules<T>>[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization'>;
authorization<AuthRuleType extends Authorization<any, any, any>>(rules: Exclude<AuthRuleType, ConflictingAuthRules<T>>[]): ModelType<SetTypeSubArg<T, 'authorization', AuthRuleType[]>, K | 'authorization'>;
}, K>;

@@ -93,0 +93,0 @@ /**

@@ -8,3 +8,3 @@ import { Brand, SetTypeSubArg } from '@aws-amplify/data-schema-types';

required: boolean;
authorization: Authorization<any, any>[];
authorization: Authorization<any, any, any>[];
};

@@ -15,3 +15,3 @@ export type RefTypeParamShape = {

required: boolean;
authorization: Authorization<any, any>[];
authorization: Authorization<any, any, any>[];
};

@@ -27,3 +27,3 @@ export type RefType<T extends RefTypeParamShape, K extends keyof RefType<T> = never, Auth = undefined> = Brand<Omit<{

*/
authorization<AuthRuleType extends Authorization<any, any>>(rules: AuthRuleType[]): RefType<T, K | 'authorization', AuthRuleType>;
authorization<AuthRuleType extends Authorization<any, any, any>>(rules: AuthRuleType[]): RefType<T, K | 'authorization', AuthRuleType>;
}, K> & {

@@ -30,0 +30,0 @@ [__auth]?: Auth;

@@ -114,3 +114,3 @@ "use strict";

function customOperationToGql(typeName, typeDef) {
const { arguments: fieldArgs, returnType, authorization } = typeDef.data;
const { arguments: fieldArgs, returnType, authorization, functionRef, } = typeDef.data;
const { authString } = calculateAuth(authorization);

@@ -125,3 +125,4 @@ const resolvedArg = refFieldToGql(returnType.data);

}
const gqlField = `${sig}: ${resolvedArg} ${authString}`;
const fnString = functionRef ? `@function(name: "${functionRef}") ` : '';
const gqlField = `${sig}: ${resolvedArg} ${fnString}${authString}`;
return { gqlField, models: implicitModels };

@@ -427,3 +428,6 @@ }

const [partitionKey] = identifier;
const { authString, authFields } = calculateAuth(typeDef.data.authorization);
const mostRelevantAuthRules = typeDef.data.authorization.length > 0
? typeDef.data.authorization
: schema.data.authorization;
const { authString, authFields } = calculateAuth(mostRelevantAuthRules);
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);

@@ -452,12 +456,12 @@ const { gqlFields, models } = processFields({

};
function generateCustomOperationTypes(fields) {
function generateCustomOperationTypes({ queries, mutations, subscriptions, }) {
const types = [];
if (fields.mutations.length > 0) {
types.push(`type Mutation {\n ${fields.mutations.join('\n ')}\n}`);
if (mutations.length > 0) {
types.push(`type Mutation {\n ${mutations.join('\n ')}\n}`);
}
if (fields.queries.length > 0) {
types.push(`type Query {\n ${fields.queries.join('\n ')}\n}`);
if (queries.length > 0) {
types.push(`type Query {\n ${queries.join('\n ')}\n}`);
}
if (fields.subscriptions.length > 0) {
types.push(`type Subscription {\n ${fields.subscriptions.join('\n ')}\n}`);
if (subscriptions.length > 0) {
types.push(`type Subscription {\n ${subscriptions.join('\n ')}\n}`);
}

@@ -464,0 +468,0 @@ return types;

{
"name": "@aws-amplify/data-schema",
"version": "0.12.1",
"version": "0.12.2",
"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