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

@aws-amplify/appsync-modelgen-plugin

Package Overview
Dependencies
Maintainers
6
Versions
289
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-amplify/appsync-modelgen-plugin - npm Package Compare versions

Comparing version 1.23.2-dev.4 to 1.23.2-dev.5

2

lib/languages/swift-declaration-block.d.ts

@@ -7,3 +7,3 @@ import { NameNode, StringValueNode } from 'graphql';

}
export declare type Access = 'private' | 'public' | 'DEFAULT';
export declare type Access = 'private' | 'public' | 'internal' | 'DEFAULT';
export declare type VariableFlags = {

@@ -10,0 +10,0 @@ isList?: boolean;

@@ -1,3 +0,3 @@

export declare const directives = "\n # model directive\n directive @model(queries: ModelQueryMap, mutations: ModelMutationMap, subscriptions: ModelSubscriptionMap) on OBJECT\n input ModelMutationMap {\n create: String\n update: String\n delete: String\n }\n input ModelQueryMap {\n get: String\n list: String\n }\n input ModelSubscriptionMap {\n onCreate: [String]\n onUpdate: [String]\n onDelete: [String]\n level: ModelSubscriptionLevel\n }\n enum ModelSubscriptionLevel {\n off\n public\n on\n }\n\n # Key directive\n directive @key(name: String, fields: [String!]!, queryField: String) repeatable on OBJECT\n\n # Connection directive\n directive @connection(\n name: String\n keyField: String\n sortField: String\n keyName: String\n limit: Int\n fields: [String!]\n ) on FIELD_DEFINITION\n\n directive @auth(rules: [AuthRule!]!) on OBJECT | FIELD_DEFINITION\n\n input AuthRule {\n # Specifies the auth rule's strategy. Allowed values are 'owner', 'groups', 'public', 'private'.\n allow: AuthStrategy!\n\n # Legacy name for identityClaim\n identityField: String @deprecated(reason: \"The 'identityField' argument is replaced by the 'identityClaim'.\")\n\n # Specifies the name of the provider to use for the rule. This overrides the default provider\n # when 'public' and 'private' AuthStrategy is used. Specifying a provider for 'owner' or 'groups'\n # are not allowed.\n provider: AuthProvider\n\n # Specifies the name of the claim to look for on the request's JWT token\n # from Cognito User Pools (and in the future OIDC) that contains the identity\n # of the user. If 'allow' is 'groups', this value should point to a list of groups\n # in the claims. If 'allow' is 'owner', this value should point to the logged in user identity string.\n # Defaults to \"cognito:username\" for Cognito User Pools auth.\n identityClaim: String\n\n # Allows for custom config of 'groups' which is validated against the JWT\n # Specifies a static list of groups that should have access to the object\n groupClaim: String\n\n # Allowed when the 'allow' argument is 'owner'.\n # Specifies the field of type String or [String] that contains owner(s) that can access the object.\n ownerField: String # defaults to \"owner\"\n # Allowed when the 'allow' argument is 'groups'.\n # Specifies the field of type String or [String] that contains group(s) that can access the object.\n groupsField: String\n\n # Allowed when the 'allow' argument is 'groups'.\n # Specifies a static list of groups that should have access to the object.\n groups: [String]\n\n # Specifies operations to which this auth rule should be applied.\n operations: [ModelOperation]\n\n # Deprecated. It is recommended to use the 'operations' arguments.\n queries: [ModelQuery] @deprecated(reason: \"The 'queries' argument will be replaced by the 'operations' argument in a future release.\")\n\n # Deprecated. It is recommended to use the 'operations' arguments.\n mutations: [ModelMutation]\n @deprecated(reason: \"The 'mutations' argument will be replaced by the 'operations' argument in a future release.\")\n }\n\n enum AuthStrategy {\n owner\n groups\n private\n public\n }\n\n enum AuthProvider {\n apiKey\n iam\n oidc\n userPools\n }\n\n enum ModelOperation {\n create\n update\n delete\n read\n }\n\n enum ModelQuery @deprecated(reason: \"ModelQuery will be replaced by the 'ModelOperation' in a future release.\") {\n get\n list\n }\n\n enum ModelMutation @deprecated(reason: \"ModelMutation will be replaced by the 'ModelOperation' in a future release.\") {\n create\n update\n delete\n }\n\n directive @searchable(queries: SearchableQueryMap) on OBJECT\n\n input SearchableQueryMap {\n search: String\n }\n\n directive @deprecated(reason: String) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ENUM | ENUM_VALUE\n";
export declare const directives = "\n # model directive\n directive @model(\n queries: ModelQueryMap\n mutations: ModelMutationMap\n subscriptions: ModelSubscriptionMap\n timestamps: TimestampConfiguration\n ) on OBJECT\n input ModelMutationMap {\n create: String\n update: String\n delete: String\n }\n input ModelQueryMap {\n get: String\n list: String\n }\n input ModelSubscriptionMap {\n onCreate: [String]\n onUpdate: [String]\n onDelete: [String]\n level: ModelSubscriptionLevel\n }\n enum ModelSubscriptionLevel {\n off\n public\n on\n }\n input TimestampConfiguration {\n createdAt: String\n updatedAt: String\n }\n\n # Key directive\n directive @key(name: String, fields: [String!]!, queryField: String) repeatable on OBJECT\n\n # Connection directive\n directive @connection(\n name: String\n keyField: String\n sortField: String\n keyName: String\n limit: Int\n fields: [String!]\n ) on FIELD_DEFINITION\n\n directive @auth(rules: [AuthRule!]!) on OBJECT | FIELD_DEFINITION\n\n input AuthRule {\n # Specifies the auth rule's strategy. Allowed values are 'owner', 'groups', 'public', 'private'.\n allow: AuthStrategy!\n\n # Legacy name for identityClaim\n identityField: String @deprecated(reason: \"The 'identityField' argument is replaced by the 'identityClaim'.\")\n\n # Specifies the name of the provider to use for the rule. This overrides the default provider\n # when 'public' and 'private' AuthStrategy is used. Specifying a provider for 'owner' or 'groups'\n # are not allowed.\n provider: AuthProvider\n\n # Specifies the name of the claim to look for on the request's JWT token\n # from Cognito User Pools (and in the future OIDC) that contains the identity\n # of the user. If 'allow' is 'groups', this value should point to a list of groups\n # in the claims. If 'allow' is 'owner', this value should point to the logged in user identity string.\n # Defaults to \"cognito:username\" for Cognito User Pools auth.\n identityClaim: String\n\n # Allows for custom config of 'groups' which is validated against the JWT\n # Specifies a static list of groups that should have access to the object\n groupClaim: String\n\n # Allowed when the 'allow' argument is 'owner'.\n # Specifies the field of type String or [String] that contains owner(s) that can access the object.\n ownerField: String # defaults to \"owner\"\n # Allowed when the 'allow' argument is 'groups'.\n # Specifies the field of type String or [String] that contains group(s) that can access the object.\n groupsField: String\n\n # Allowed when the 'allow' argument is 'groups'.\n # Specifies a static list of groups that should have access to the object.\n groups: [String]\n\n # Specifies operations to which this auth rule should be applied.\n operations: [ModelOperation]\n\n # Deprecated. It is recommended to use the 'operations' arguments.\n queries: [ModelQuery] @deprecated(reason: \"The 'queries' argument will be replaced by the 'operations' argument in a future release.\")\n\n # Deprecated. It is recommended to use the 'operations' arguments.\n mutations: [ModelMutation]\n @deprecated(reason: \"The 'mutations' argument will be replaced by the 'operations' argument in a future release.\")\n }\n\n enum AuthStrategy {\n owner\n groups\n private\n public\n }\n\n enum AuthProvider {\n apiKey\n iam\n oidc\n userPools\n }\n\n enum ModelOperation {\n create\n update\n delete\n read\n }\n\n enum ModelQuery @deprecated(reason: \"ModelQuery will be replaced by the 'ModelOperation' in a future release.\") {\n get\n list\n }\n\n enum ModelMutation @deprecated(reason: \"ModelMutation will be replaced by the 'ModelOperation' in a future release.\") {\n create\n update\n delete\n }\n\n directive @searchable(queries: SearchableQueryMap) on OBJECT\n\n input SearchableQueryMap {\n search: String\n }\n\n directive @deprecated(reason: String) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ENUM | ENUM_VALUE\n";
export declare const scalars: string;
//# sourceMappingURL=supported-directives.d.ts.map

@@ -6,3 +6,8 @@ "use strict";

# model directive
directive @model(queries: ModelQueryMap, mutations: ModelMutationMap, subscriptions: ModelSubscriptionMap) on OBJECT
directive @model(
queries: ModelQueryMap
mutations: ModelMutationMap
subscriptions: ModelSubscriptionMap
timestamps: TimestampConfiguration
) on OBJECT
input ModelMutationMap {

@@ -28,2 +33,6 @@ create: String

}
input TimestampConfiguration {
createdAt: String
updatedAt: String
}

@@ -30,0 +39,0 @@ # Key directive

@@ -42,3 +42,4 @@ import { JavaDeclarationBlock } from '../languages/java-declaration-block';

protected getNonConnectedField(model: CodeGenModel): CodeGenField[];
protected getWritableFields(model: CodeGenModel): CodeGenField[];
}
//# sourceMappingURL=appsync-java-visitor.d.ts.map

@@ -133,4 +133,5 @@ "use strict";

classDeclarationBlock.annotate(annotations);
const queryFields = this.getWritableFields(model);
queryFields.forEach(field => this.generateQueryFields(model, field, classDeclarationBlock));
const nonConnectedFields = this.getNonConnectedField(model);
nonConnectedFields.forEach(field => this.generateQueryFields(model, field, classDeclarationBlock));
model.fields.forEach(field => {

@@ -214,3 +215,3 @@ const value = nonConnectedFields.includes(field) ? '' : 'null';

classDeclarationBlock.addClassMember(fieldName, fieldType, value, annotations, 'private', {
final: true,
final: !field.isReadOnly,
});

@@ -226,4 +227,4 @@ }

generateStepBuilderInterfaces(model, isModel = true) {
const nonNullableFields = this.getNonConnectedField(model).filter(field => !field.isNullable);
const nullableFields = this.getNonConnectedField(model).filter(field => field.isNullable);
const nonNullableFields = this.getWritableFields(model).filter(field => !field.isNullable);
const nullableFields = this.getWritableFields(model).filter(field => field.isNullable);
const requiredInterfaces = nonNullableFields.filter((field) => !this.READ_ONLY_FIELDS.includes(field.name));

@@ -262,8 +263,6 @@ const interfaces = requiredInterfaces.map((field, idx) => {

generateBuilderClass(model, classDeclaration, isModel = true) {
const nonNullableFields = this.getNonConnectedField(model).filter(field => !field.isNullable);
const nullableFields = this.getNonConnectedField(model).filter(field => field.isNullable);
const nonNullableFields = this.getWritableFields(model).filter(field => !field.isNullable);
const nullableFields = this.getWritableFields(model).filter(field => field.isNullable);
const stepFields = nonNullableFields.filter((field) => !this.READ_ONLY_FIELDS.includes(field.name));
const stepInterfaces = stepFields.map((field) => {
return this.getStepInterfaceName(field.name);
});
const stepInterfaces = stepFields.map((field) => this.getStepInterfaceName(field.name));
const builderClassDeclaration = new java_declaration_block_1.JavaDeclarationBlock()

@@ -280,3 +279,3 @@ .access('public')

const buildImplementation = isModel ? [`String id = this.id != null ? this.id : UUID.randomUUID().toString();`, ''] : [''];
const buildParams = this.getNonConnectedField(model)
const buildParams = this.getWritableFields(model)
.map(field => this.getFieldName(field))

@@ -333,9 +332,7 @@ .join(',\n');

.extends(['Builder']);
const nonNullableFields = this.getNonConnectedField(model)
const nonNullableFields = this.getWritableFields(model)
.filter(field => !field.isNullable)
.filter(f => (isModel ? f.name !== 'id' : true));
const nullableFields = this.getNonConnectedField(model).filter(field => field.isNullable);
const constructorArguments = this.getNonConnectedField(model).map(field => {
return { name: this.getStepFunctionArgumentName(field), type: this.getNativeType(field) };
});
const nullableFields = this.getWritableFields(model).filter(field => field.isNullable);
const constructorArguments = this.getWritableFields(model).map(field => ({ name: this.getStepFunctionArgumentName(field), type: this.getNativeType(field) }));
const stepBuilderInvocation = [...nonNullableFields, ...nullableFields].map(field => {

@@ -364,3 +361,3 @@ const methodName = this.getStepFunctionName(field);

generateCopyOfBuilderMethod(model, classDeclaration) {
const args = visitor_plugin_common_1.indentMultiline(this.getNonConnectedField(model)
const args = visitor_plugin_common_1.indentMultiline(this.getWritableFields(model)
.map(field => this.getFieldName(field))

@@ -391,3 +388,3 @@ .join(',\n')).trim();

const name = this.getModelName(model);
const body = this.getNonConnectedField(model)
const body = this.getWritableFields(model)
.map((field) => {

@@ -398,5 +395,3 @@ const fieldName = this.getFieldName(field);

.join('\n');
const constructorArguments = this.getNonConnectedField(model).map(field => {
return { name: this.getFieldName(field), type: this.getNativeType(field) };
});
const constructorArguments = this.getWritableFields(model).map(field => ({ name: this.getFieldName(field), type: this.getNativeType(field) }));
declarationsBlock.addClassMethod(name, null, body, constructorArguments, undefined, 'private');

@@ -466,3 +461,3 @@ }

generateBuilderMethod(model, classDeclaration) {
const requiredFields = this.getNonConnectedField(model).filter(field => !field.isNullable && !this.READ_ONLY_FIELDS.includes(field.name));
const requiredFields = this.getWritableFields(model).filter(field => !field.isNullable && !this.READ_ONLY_FIELDS.includes(field.name));
const returnType = requiredFields.length ? this.getStepInterfaceName(requiredFields[0].name) : this.getStepInterfaceName('Build');

@@ -563,2 +558,3 @@ classDeclaration.addClassMethod('builder', returnType, visitor_plugin_common_1.indentMultiline(`return new Builder();`), [], [], 'public', { static: true }, []);

authRules.length ? `authRules = ${authRules}` : '',
field.isReadOnly ? 'isReadOnly = true' : '',
].filter(arg => arg);

@@ -610,3 +606,3 @@ return `ModelField${annotationArgs.length ? `(${annotationArgs.join(', ')})` : ''}`;

}`;
const initArgs = visitor_plugin_common_1.indentMultiline(['id', ...new Array(this.getNonConnectedField(model).length - 1).fill('null')].join(',\n'));
const initArgs = visitor_plugin_common_1.indentMultiline(['id', ...new Array(this.getWritableFields(model).length - 1).fill('null')].join(',\n'));
const initBlock = `return new ${returnType}(\n${initArgs}\n);`;

@@ -624,4 +620,7 @@ classDeclaration.addClassMethod('justId', returnType, [exceptionBlock, initBlock].join('\n'), [{ name: 'id', type: 'String' }], [], 'public', { static: true }, [], [], comment);

}
getWritableFields(model) {
return this.getNonConnectedField(model).filter(f => !f.isReadOnly);
}
}
exports.AppSyncModelJavaVisitor = AppSyncModelJavaVisitor;
//# sourceMappingURL=appsync-java-visitor.js.map

@@ -64,2 +64,3 @@ import { NormalizedScalarsMap } from '@graphql-codegen/visitor-plugin-common';

isArrayNullable?: boolean;
isReadOnly?: boolean;
attributes?: JSONModelFieldAttributes;

@@ -66,0 +67,0 @@ association?: AssociationType;

@@ -109,2 +109,5 @@ "use strict";

}
if (field.isReadOnly !== undefined) {
fieldMeta.isReadOnly = field.isReadOnly;
}
const association = this.getFieldAssociation(field);

@@ -111,0 +114,0 @@ if (association) {

import { SwiftDeclarationBlock } from '../languages/swift-declaration-block';
import { AppSyncModelVisitor, CodeGenField, CodeGenModel } from './appsync-visitor';
export declare class AppSyncSwiftVisitor extends AppSyncModelVisitor {
import { AppSyncModelVisitor, CodeGenField, CodeGenModel, RawAppSyncModelConfig, ParsedAppSyncModelConfig } from './appsync-visitor';
export declare class AppSyncSwiftVisitor<TRawConfig extends RawAppSyncModelConfig = RawAppSyncModelConfig, TPluginConfig extends ParsedAppSyncModelConfig = ParsedAppSyncModelConfig> extends AppSyncModelVisitor<TRawConfig, TPluginConfig> {
protected modelExtensionImports: string[];

@@ -21,3 +21,4 @@ protected imports: string[];

protected generateAuthRules(model: CodeGenModel): string;
protected getWritableFields(model: CodeGenModel): CodeGenField[];
}
//# sourceMappingURL=appsync-swift-visitor.d.ts.map

@@ -58,4 +58,10 @@ "use strict";

});
const initImpl = this.getInitBody(obj.fields);
structBlock.addClassMethod('init', null, initImpl, obj.fields.map(field => {
const initParams = this.getWritableFields(obj);
const initImpl = `self.init(${visitor_plugin_common_1.indentMultiline(obj.fields
.map(field => {
const fieldName = swift_declaration_block_1.escapeKeywords(this.getFieldName(field));
return field.isReadOnly ? `${fieldName}: nil` : `${fieldName}: ${fieldName}`;
})
.join(',\n')).trim()})`;
structBlock.addClassMethod('init', null, initImpl, initParams.map(field => {
const listType = field.connectionInfo ? swift_declaration_block_1.ListType.LIST : swift_declaration_block_1.ListType.ARRAY;

@@ -74,2 +80,16 @@ return {

}), 'public', {});
structBlock.addClassMethod('init', null, this.getInitBody(obj.fields), obj.fields.map(field => {
const listType = field.connectionInfo ? swift_declaration_block_1.ListType.LIST : swift_declaration_block_1.ListType.ARRAY;
return {
name: this.getFieldName(field),
type: this.getNativeType(field),
value: field.name === 'id' ? 'UUID().uuidString' : undefined,
flags: {
optional: field.isNullable,
isList: field.isList,
isEnum: this.isEnumType(field),
listType: field.isList ? listType : undefined,
},
};
}), 'internal', {});
result.push(structBlock.string);

@@ -149,5 +169,3 @@ });

const keysName = lower_case_first_1.lowerCaseFirst(model.name);
const fields = model.fields.map(field => {
return this.generateFieldSchema(field, keysName);
});
const fields = model.fields.map(field => this.generateFieldSchema(field, keysName));
const authRules = this.generateAuthRules(model);

@@ -169,5 +187,3 @@ const closure = [

generateClassLoader() {
const structList = Object.values(this.modelMap).map(typeObj => {
return `${this.getModelName(typeObj)}.self`;
});
const structList = Object.values(this.modelMap).map(typeObj => `${this.getModelName(typeObj)}.self`);
const result = [...this.modelExtensionImports, ''];

@@ -202,2 +218,3 @@ const classDeclaration = new swift_declaration_block_1.SwiftDeclarationBlock()

let ofType;
let isReadOnly = '';
const isEnumType = this.isEnumType(field);

@@ -243,3 +260,6 @@ const isModelType = this.isModelType(field);

}
const args = [`${name}`, `is: ${isRequired}`, `ofType: ${ofType}`].filter(arg => arg).join(', ');
if (field.isReadOnly) {
isReadOnly = 'isReadOnly: true';
}
const args = [`${name}`, `is: ${isRequired}`, isReadOnly, `ofType: ${ofType}`].filter(arg => arg).join(', ');
return `.field(${args})`;

@@ -311,4 +331,7 @@ }

}
getWritableFields(model) {
return model.fields.filter(f => !f.isReadOnly);
}
}
exports.AppSyncSwiftVisitor = AppSyncSwiftVisitor;
//# sourceMappingURL=appsync-swift-visitor.js.map

@@ -14,2 +14,3 @@ import { BaseVisitor, NormalizedScalarsMap, ParsedConfig, RawConfig } from '@graphql-codegen/visitor-plugin-common';

directives?: string;
isTimestampFieldsAdded?: boolean;
}

@@ -19,2 +20,4 @@ export interface ParsedAppSyncModelConfig extends ParsedConfig {

generate?: CodeGenGenerateEnum;
target?: string;
isTimestampFieldsAdded?: boolean;
}

@@ -31,2 +34,3 @@ export declare type CodeGenArgumentsMap = Record<string, any>;

connectionInfo?: CodeGenFieldConnection;
isReadOnly?: boolean;
};

@@ -95,2 +99,3 @@ export declare type TypeInfo = {

protected pluralizeModelName(model: CodeGenModel): string;
protected addTimestampFields(model: CodeGenModel, directive: CodeGenDirective): void;
get models(): CodeGenModelMap;

@@ -97,0 +102,0 @@ get enums(): Record<string, CodeGenEnum>;

@@ -24,2 +24,4 @@ "use strict";

})(CodeGenGenerateEnum = exports.CodeGenGenerateEnum || (exports.CodeGenGenerateEnum = {}));
const DEFAULT_CREATED_TIME = 'createdAt';
const DEFAULT_UPDATED_TIME = 'updatedAt';
class AppSyncModelVisitor extends visitor_plugin_common_1.BaseVisitor {

@@ -30,2 +32,4 @@ constructor(_schema, rawConfig, additionalConfig, defaultScalars = visitor_plugin_common_1.DEFAULT_SCALARS) {

scalars: visitor_plugin_common_1.buildScalars(_schema, rawConfig.scalars || '', defaultScalars),
target: rawConfig.target,
isTimestampFieldsAdded: rawConfig.isTimestampFieldsAdded,
});

@@ -59,3 +63,4 @@ this._schema = _schema;

const fields = node.fields;
if (directives.find(directive => directive.name === 'model')) {
const modelDirective = directives.find(directive => directive.name === 'model');
if (modelDirective) {
const model = {

@@ -68,2 +73,3 @@ name: node.name.value,

this.ensureIdField(model);
this.addTimestampFields(model, modelDirective);
this.sortFields(model);

@@ -324,2 +330,33 @@ this.modelMap[node.name.value] = model;

}
addTimestampFields(model, directive) {
if (!this.config.isTimestampFieldsAdded) {
return;
}
const target = this.config.target;
if (target === 'dart') {
return;
}
if (directive.name !== 'model') {
return;
}
const timestamps = directive.arguments.timestamps;
const createdAtField = {
name: (timestamps === null || timestamps === void 0 ? void 0 : timestamps.createdAt) || DEFAULT_CREATED_TIME,
directives: [],
type: 'AWSDateTime',
isList: false,
isNullable: true,
isReadOnly: true,
};
const updatedAtField = {
name: (timestamps === null || timestamps === void 0 ? void 0 : timestamps.updatedAt) || DEFAULT_UPDATED_TIME,
directives: [],
type: 'AWSDateTime',
isList: false,
isNullable: true,
isReadOnly: true,
};
fieldUtils_1.addFieldToModel(model, createdAtField);
fieldUtils_1.addFieldToModel(model, updatedAtField);
}
get models() {

@@ -326,0 +363,0 @@ return this.modelMap;

{
"name": "@aws-amplify/appsync-modelgen-plugin",
"version": "1.23.2-dev.4+b3b03a0",
"version": "1.23.2-dev.5+f611e94",
"repository": {

@@ -73,3 +73,3 @@ "type": "git",

},
"gitHead": "b3b03a08fb78008702f6b50b154929880be26cb4"
"gitHead": "f611e94ef8cbd37cf8e8f356df83adcb9a8d3465"
}

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

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

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

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