resources

package
v1.2.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const OpenApiInternal = "internal"
View Source
const OpenApiMeta = "meta"

Variables

View Source
var AuditLogResource = &model.Resource{
	Name:      "AuditLog",
	Namespace: "system",
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "audit_log",
	},
	Immutable: true,
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		{
			Name:     "namespace",
			Length:   256,
			Type:     model.ResourceProperty_STRING,
			Required: true,
		},
		{
			Name:     "resource",
			Length:   256,
			Type:     model.ResourceProperty_STRING,
			Required: true,
		},
		{
			Name:     "recordId",
			Length:   256,
			Type:     model.ResourceProperty_STRING,
			Required: true,
			Annotations: map[string]string{
				annotations.SourceDef: "record_id",
			},
		},
		{
			Name:     "time",
			Type:     model.ResourceProperty_TIMESTAMP,
			Required: true,
		},
		{
			Name:     "username",
			Type:     model.ResourceProperty_STRING,
			Required: true,
		},
		{
			Name:     "operation",
			Type:     model.ResourceProperty_ENUM,
			Required: true,
			EnumValues: []string{
				"CREATE",
				"UPDATE",
				"DELETE",
			},
		},
		{
			Name:     "properties",
			Type:     model.ResourceProperty_OBJECT,
			Required: false,
		},
		special.AnnotationsProperty,
	},
	Annotations: map[string]string{
		annotations.OpenApiGroup:     OpenApiInternal,
		annotations.BypassExtensions: annotations.Enabled,
	},
}
View Source
var DataSourceResource = &model.Resource{
	Name:      "DataSource",
	Namespace: "system",
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "data_source",
	},
	Types: []*model.ResourceSubType{
		special.AuditDataSubType,
	},
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		special.AuditProperty,
		{
			Name:     "name",
			Length:   64,
			Unique:   true,
			Type:     model.ResourceProperty_STRING,
			Required: true,
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:     "description",
			Length:   64,
			Type:     model.ResourceProperty_STRING,
			Required: false,
			Annotations: map[string]string{
				annotations.AllowEmptyPrimitive: annotations.Enabled,
			},
		},
		{
			Name:     "backend",
			Type:     model.ResourceProperty_ENUM,
			Required: true,
			EnumValues: []string{
				"POSTGRESQL",
				"MYSQL",
				"MONGODB",
				"REDIS",
			},
		},
		{
			Name:     "options",
			Required: true,
			Type:     model.ResourceProperty_MAP,
			Item: &model.ResourceProperty{
				Type: model.ResourceProperty_STRING,
			},
		},
	},
	Annotations: map[string]string{
		annotations.EnableAudit:  "true",
		annotations.OpenApiGroup: OpenApiInternal,
	},
}
View Source
var ExtensionResource = &model.Resource{
	Name:      "Extension",
	Namespace: "system",
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "extension",
	},
	Types: []*model.ResourceSubType{
		sub_types.BooleanExpression,
		sub_types.PairExpression,
		sub_types.RegexMatchExpression,
		sub_types.Expression,
		special.AuditDataSubType,
		{
			Name: "FunctionCall",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name:     "host",
					Type:     model.ResourceProperty_STRING,
					Required: true,
				},
				{
					Name:     "functionName",
					Type:     model.ResourceProperty_STRING,
					Required: true,
				},
			},
		},
		{
			Name: "HttpCall",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name:     "uri",
					Type:     model.ResourceProperty_STRING,
					Required: true,
				},
				{
					Name:     "method",
					Type:     model.ResourceProperty_STRING,
					Required: true,
				},
			},
		},
		{
			Name: "ChannelCall",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name:     "channelKey",
					Type:     model.ResourceProperty_STRING,
					Required: true,
				},
			},
		},
		{
			Name: "ExternalCall",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name:    "functionCall",
					Type:    model.ResourceProperty_STRUCT,
					TypeRef: util.Pointer("FunctionCall"),
				},
				{
					Name:    "httpCall",
					Type:    model.ResourceProperty_STRUCT,
					TypeRef: util.Pointer("HttpCall"),
				},
				{
					Name:    "channelCall",
					Type:    model.ResourceProperty_STRUCT,
					TypeRef: util.Pointer("ChannelCall"),
				},
			},
		},
		{
			Name: "EventSelector",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name: "actions",
					Type: model.ResourceProperty_LIST,
					Item: &model.ResourceProperty{
						Name: "action",
						Type: model.ResourceProperty_ENUM,
						EnumValues: []string{
							"CREATE",
							"UPDATE",
							"DELETE",
							"GET",
							"LIST",
							"OPERATE",
						},
						Annotations: map[string]string{
							annotations.TypeName: "EventAction",
						},
					},
				},
				{
					Name:    "recordSelector",
					Type:    model.ResourceProperty_STRUCT,
					TypeRef: util.Pointer(sub_types.BooleanExpression.Name),
				},
				{
					Name: "namespaces",
					Type: model.ResourceProperty_LIST,
					Item: &model.ResourceProperty{Type: model.ResourceProperty_STRING},
				},
				{
					Name: "resources",
					Type: model.ResourceProperty_LIST,
					Item: &model.ResourceProperty{Type: model.ResourceProperty_STRING},
				},
				{
					Name: "ids",
					Type: model.ResourceProperty_LIST,
					Item: &model.ResourceProperty{Type: model.ResourceProperty_STRING},
				},
				special.AnnotationsProperty,
			},
		},
		{
			Name: "RecordSearchParams",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name:    "query",
					Type:    model.ResourceProperty_STRUCT,
					TypeRef: &sub_types.BooleanExpression.Name,
				},
				{
					Name: "limit",
					Type: model.ResourceProperty_INT32,
				},
				{
					Name: "offset",
					Type: model.ResourceProperty_INT32,
				},
				{
					Name: "resolveReferences",
					Type: model.ResourceProperty_LIST,
					Item: &model.ResourceProperty{
						Type: model.ResourceProperty_STRING,
					},
				},
			},
		},
		{
			Name: "Event",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name:      "id",
					Type:      model.ResourceProperty_STRING,
					Required:  true,
					Immutable: true,
				},
				{
					Name: "action",
					Type: model.ResourceProperty_ENUM,
					EnumValues: []string{
						"CREATE",
						"UPDATE",
						"DELETE",
						"GET",
						"LIST",
						"OPERATE",
					},
					Required: true,
				},
				{
					Name:    "recordSearchParams",
					Type:    model.ResourceProperty_STRUCT,
					TypeRef: util.Pointer("RecordSearchParams"),
				},
				{
					Name: "actionSummary",
					Type: model.ResourceProperty_STRING,
				},
				{
					Name: "actionDescription",
					Type: model.ResourceProperty_STRING,
				},
				{
					Name: "resource",
					Type: model.ResourceProperty_REFERENCE,
					Reference: &model.Reference{
						Resource: "Resource",
					},
				},
				{
					Name: "records",
					Type: model.ResourceProperty_LIST,
					Item: &model.ResourceProperty{
						Type: model.ResourceProperty_REFERENCE,
						Reference: &model.Reference{
							Resource: "Record",
						},
					},
				},
				{
					Name: "finalizes",
					Type: model.ResourceProperty_BOOL,
				},
				{
					Name: "sync",
					Type: model.ResourceProperty_BOOL,
				},
				{
					Name: "time",
					Type: model.ResourceProperty_TIMESTAMP,
				},
				{
					Name: "total",
					Type: model.ResourceProperty_INT64,
				},
				{
					Name: "actionName",
					Type: model.ResourceProperty_STRING,
				},
				{
					Name: "input",
					Type: model.ResourceProperty_OBJECT,
				},
				{
					Name: "output",
					Type: model.ResourceProperty_OBJECT,
				},
				special.AnnotationsProperty,
				{
					Name:    "error",
					Type:    model.ResourceProperty_STRUCT,
					TypeRef: util.Pointer("Error"),
				},
			},
		},
		{
			Name: "ErrorField",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name: "recordId",
					Type: model.ResourceProperty_STRING,
				},
				{
					Name: "property",
					Type: model.ResourceProperty_STRING,
				},
				{
					Name: "message",
					Type: model.ResourceProperty_STRING,
				},
				{
					Name: "value",
					Type: model.ResourceProperty_OBJECT,
				},
			},
		},
		{
			Name: "Error",
			Annotations: map[string]string{
				annotations.CommonType: annotations.Enabled,
			},
			Properties: []*model.ResourceProperty{
				{
					Name: "code",
					Type: model.ResourceProperty_ENUM,
					EnumValues: []string{
						"UNKNOWN_ERROR",
						"RECORD_NOT_FOUND",
						"UNABLE_TO_LOCATE_PRIMARY_KEY",
						"INTERNAL_ERROR",
						"PROPERTY_NOT_FOUND",
						"RECORD_VALIDATION_ERROR",
						"RESOURCE_VALIDATION_ERROR",
						"AUTHENTICATION_FAILED",
						"ALREADY_EXISTS",
						"ACCESS_DENIED",
						"BACKEND_ERROR",
						"UNIQUE_VIOLATION",
						"REFERENCE_VIOLATION",
						"RESOURCE_NOT_FOUND",
						"UNSUPPORTED_OPERATION",
						"EXTERNAL_BACKEND_COMMUNICATION_ERROR",
						"EXTERNAL_BACKEND_ERROR",
						"RATE_LIMIT_ERROR",
					},
				},
				{
					Name: "message",
					Type: model.ResourceProperty_STRING,
				},
				{
					Name: "fields",
					Type: model.ResourceProperty_LIST,
					Item: &model.ResourceProperty{
						Type:    model.ResourceProperty_STRUCT,
						TypeRef: util.Pointer("ErrorField"),
					},
				},
			},
		},
	},
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		special.AuditProperty,
		{
			Name:     "name",
			Length:   256,
			Type:     model.ResourceProperty_STRING,
			Unique:   true,
			Required: true,
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:     "description",
			Length:   1024,
			Type:     model.ResourceProperty_STRING,
			Required: false,
		},
		{
			Name:     "selector",
			Type:     model.ResourceProperty_STRUCT,
			Required: false,
			TypeRef:  util.Pointer("EventSelector"),
		},
		{
			Name:     "order",
			Type:     model.ResourceProperty_INT32,
			Required: true,
		},
		{
			Name:     "finalizes",
			Type:     model.ResourceProperty_BOOL,
			Required: true,
		},
		{
			Name:     "sync",
			Type:     model.ResourceProperty_BOOL,
			Required: true,
		},
		{
			Name:     "responds",
			Type:     model.ResourceProperty_BOOL,
			Required: true,
		},
		{
			Name:     "call",
			Type:     model.ResourceProperty_STRUCT,
			Required: true,
			TypeRef:  util.Pointer("ExternalCall"),
		},
		special.AnnotationsProperty,
	},
	Annotations: map[string]string{
		annotations.EnableAudit:  "true",
		annotations.OpenApiGroup: OpenApiInternal,
	},
}
View Source
var NamespaceResource = &model.Resource{
	Name:      "Namespace",
	Namespace: "system",
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "namespace",
	},
	Types: []*model.ResourceSubType{
		special.AuditDataSubType,
	},
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		special.AuditProperty,
		{
			Name:      "name",
			Type:      model.ResourceProperty_STRING,
			Length:    256,
			Required:  true,
			Unique:    true,
			Immutable: true,
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:     "description",
			Type:     model.ResourceProperty_STRING,
			Length:   256,
			Required: false,
		},
		{
			Name:     "details",
			Type:     model.ResourceProperty_OBJECT,
			Required: false,
		},
	},
	Annotations: map[string]string{
		annotations.EnableAudit:  "true",
		annotations.OpenApiGroup: OpenApiInternal,
	},
}
View Source
var PermissionResource = &model.Resource{
	Name:        "Permission",
	Title:       util.Pointer("Permission"),
	Description: util.Pointer("Permission is a resource that defines the access control rules for resources for users."),
	Namespace:   "system",
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "permission",
	},
	Types: []*model.ResourceSubType{
		special.AuditDataSubType,
	},
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		special.AuditProperty,
		{
			Name:         "namespace",
			Title:        util.Pointer("Namespace"),
			Description:  util.Pointer(`The namespace(name) of the resource. If given it will be used to match the resource by namespace.`),
			Type:         model.ResourceProperty_STRING,
			Length:       255,
			ExampleValue: structpb.NewStringValue("default"),
		},
		{
			Name:         "resource",
			Title:        util.Pointer("Resource"),
			Description:  util.Pointer(`The name of the resource. If given it will be used to match the resource by name.`),
			Type:         model.ResourceProperty_STRING,
			Length:       255,
			ExampleValue: structpb.NewStringValue("Book"),
		},
		{
			Name:  "property",
			Title: util.Pointer("Property"),
			Description: util.Pointer(`The name of the property.
property and propertyValue are used to match the resource by property value. If record matches property => propertyValue then the permission will be considered. If not, it will be ignored.
Besides that we also have propertyMode which indicate how to match the property value.
If propertyMode is PROPERTY_MATCH_ONLY then only the given property is allowed to be updated, if any other property is sent and not matching by any permission, it will cause an error.
Like for example, you want user to update only title property of resource and to not able to update any other property.
But PROPERTY_MATCH_ANY means that if any of the property is matching then the permission will be considered. It is more useful for owner matching or etc.
For example you want to allow records where owner is user own, etc.
`),
			Type:         model.ResourceProperty_STRING,
			Length:       255,
			Required:     false,
			ExampleValue: structpb.NewStringValue("author"),
		},
		{
			Name:         "propertyValue",
			Title:        util.Pointer("Property Value"),
			Description:  util.Pointer(`The value of the property. It is used by combination with property, please see the description of property.`),
			Type:         model.ResourceProperty_STRING,
			Length:       255,
			Required:     false,
			ExampleValue: structpb.NewStringValue("John Doe"),
		},
		{
			Name:        "propertyMode",
			Title:       util.Pointer("Property Mode"),
			Description: util.Pointer(`The mode of the property. It is used by combination with property and property value, please see the description of property.`),
			Type:        model.ResourceProperty_ENUM,
			Length:      255,
			EnumValues: []string{
				"PROPERTY_MATCH_ONLY",
				"PROPERTY_MATCH_ANY",
			},
		},
		{
			Name:         "operation",
			Title:        util.Pointer("Operation"),
			Description:  util.Pointer(`The operation of the permission. It is used to match the operation of the request. If given it will be used to match the operation of the request.`),
			Type:         model.ResourceProperty_ENUM,
			Length:       255,
			Required:     true,
			DefaultValue: structpb.NewStringValue("FULL"),
			EnumValues: []string{
				"READ",
				"CREATE",
				"UPDATE",
				"DELETE",
				"FULL",
			},
			ExampleValue: structpb.NewStringValue("READ"),
		},
		{
			Name:        "recordIds",
			Title:       util.Pointer("Record Ids"),
			Description: util.Pointer(`The ids of the records. It is used to match the record ids of the request. If you want to match only specific records, otherwise all records will be considered`),
			Type:        model.ResourceProperty_LIST,
			Item: &model.ResourceProperty{
				Type: model.ResourceProperty_STRING,
			},
		},
		{
			Name:        "before",
			Title:       util.Pointer("Before"),
			Description: util.Pointer(`The timestamp before which the permission is valid. If given it will be used to match the timestamp of the request.`),
			Type:        model.ResourceProperty_TIMESTAMP,
		},
		{
			Name:        "after",
			Title:       util.Pointer("After"),
			Description: util.Pointer(`The timestamp after which the permission is valid. If given it will be used to match the timestamp of the request.`),
			Type:        model.ResourceProperty_TIMESTAMP,
		},
		{
			Name:        "user",
			Title:       util.Pointer("User"),
			Description: util.Pointer(`The user who has the permission. If given it will be used to match the user of the request. It is ignored by default, because if permissions is set through User this property is overrides and auto-populated by system`),
			Type:        model.ResourceProperty_REFERENCE,
			Reference: &model.Reference{
				Namespace: UserResource.Namespace,
				Resource:  UserResource.Name,
			},
		},
		{
			Name:        "role",
			Title:       util.Pointer("Role"),
			Description: util.Pointer(`The role who has the permission. If given it will be used to match the role of the request. It is ignored by default, because if permissions is set through Role this property is overrides and auto-populated by system`),
			Type:        model.ResourceProperty_REFERENCE,
			Reference: &model.Reference{
				Namespace: RoleResource.Namespace,
				Resource:  RoleResource.Name,
			},
		},
		{
			Name:        "permit",
			Title:       util.Pointer("Permit"),
			Description: util.Pointer(`The permit of the permission. If permission is matched, this property is judging field to indicate that if operation is allowed or not`),
			Required:    true,
			Length:      255,
			Type:        model.ResourceProperty_ENUM,
			EnumValues: []string{
				"ALLOW",
				"REJECT",
			},
		},
		{
			Name: "localFlags",
			Type: model.ResourceProperty_OBJECT,
		},
	},
	Annotations: map[string]string{
		annotations.EnableAudit:  annotations.Enabled,
		annotations.OpenApiGroup: OpenApiMeta,
	},
}
View Source
var PropertyType = &model.ResourceSubType{
	Name:        "Property",
	Title:       "Property",
	Description: "Property is a type that represents a property of a resource. It is like an API properties or properties of class in a programming language",
	Annotations: map[string]string{
		annotations.CommonType: annotations.Enabled,
	},
	Properties: ResourcePropertyProperties,
}
View Source
var RecordResource = &model.Resource{
	Name:        "Record",
	Title:       util.Pointer("Generic Record"),
	Description: util.Pointer("A generic record resource. All Apis are extended from Generic Record resource"),
	Namespace:   "system",
	Virtual:     true,
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		{
			Name:  "properties",
			Title: util.Pointer("Properties"),
			Description: util.Pointer(`The properties of the record. The schema of properties are defined in the resource definition. 
Here you will put the payload corresponding to the resource definition.
`),
			Type:     model.ResourceProperty_OBJECT,
			Required: true,
		},
		{
			Name: "packedProperties",
			Type: model.ResourceProperty_LIST,
			Item: &model.ResourceProperty{
				Type: model.ResourceProperty_OBJECT,
			},
			Annotations: map[string]string{
				annotations.OpenApiHide: "true",
			},
		},
	},

	Annotations: map[string]string{

		annotations.RestApiDisabled: annotations.Enabled,
	},
}
View Source
var ReferenceType = &model.ResourceSubType{
	Name:        "Reference",
	Title:       "Reference",
	Description: "Reference is a type that represents a reference to another resource. It is used to define the reference to another resource. ",
	Annotations: map[string]string{
		annotations.CommonType: annotations.Enabled,
	},
	Properties: []*model.ResourceProperty{
		{
			Name:  "resource",
			Title: util.Pointer("Resource"),
			Description: util.Pointer(`This property indicates the resource of the reference.
When providing resource, you need to provide namespace and resource name of the referenced resource.
If you don't provide namespace, it will be assumed as the same namespace with the resource.
`),
			Type: model.ResourceProperty_REFERENCE,
			Reference: &model.Reference{
				Namespace: "system",
				Resource:  "Resource",
			},
			ExampleValue: structpb.NewStructValue(&structpb.Struct{
				Fields: map[string]*structpb.Value{
					"namespace": structpb.NewStructValue(&structpb.Struct{
						Fields: map[string]*structpb.Value{
							"name": structpb.NewStringValue("test-namespace"),
						},
					}),
					"name": structpb.NewStringValue("Book"),
				},
			}),
		},
		{
			Name:  "cascade",
			Title: util.Pointer("Cascade"),
			Description: util.Pointer(`This property indicates that whether or not given reference is cascade.
If it is true, when referenced resource record is deleted, all the records that are referencing to that resource will be deleted.
`),
			Type: model.ResourceProperty_BOOL,
		},
		{
			Name:  "backReference",
			Title: util.Pointer("Back Reference"),
			Description: util.Pointer(`This property indicates that whether or not given reference is back reference.
Back reference is reverse of reference, If resource A has reference to resource B, in that case resource B can have back reference to resource A.
Back reference is used only as List.
Backreference should be the name of property in the referenced resource. (like author inside book)
For example:
	Book -> Author.
	Book will have reference to Author. And Author can have back reference to the list of books

`),
			Type:         model.ResourceProperty_STRING,
			ExampleValue: structpb.NewStringValue("author"),
		},
	},
}
View Source
var ResourceActionResource = &model.Resource{
	Name:      "ResourceAction",
	Namespace: "system",
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "resource_action",
	},
	Types: []*model.ResourceSubType{
		SubTypeType,
		ReferenceType,
		PropertyType,
		special.AuditDataSubType,
	},
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		special.AuditProperty,
		{
			Name:     "resource",
			Type:     model.ResourceProperty_REFERENCE,
			Required: true,
			Reference: &model.Reference{
				Resource:  ResourceResource.Name,
				Namespace: ResourceResource.Namespace,
				Cascade:   false,
			},
		},
		{
			Name:     "name",
			Type:     model.ResourceProperty_STRING,
			Length:   256,
			Required: true,
			Unique:   false,
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:     "title",
			Type:     model.ResourceProperty_STRING,
			Length:   256,
			Required: false,
			Unique:   false,
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:     "description",
			Type:     model.ResourceProperty_STRING,
			Length:   256,
			Required: false,
			Unique:   false,
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:         "internal",
			Type:         model.ResourceProperty_BOOL,
			Required:     true,
			DefaultValue: structpb.NewBoolValue(false),
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:     "types",
			Type:     model.ResourceProperty_LIST,
			Required: false,
			Item: &model.ResourceProperty{
				Type:    model.ResourceProperty_STRUCT,
				TypeRef: util.Pointer("SubType"),
			},
		},
		{
			Name: "input",
			Type: model.ResourceProperty_LIST,
			Item: &model.ResourceProperty{
				Type:    model.ResourceProperty_STRUCT,
				TypeRef: util.Pointer("Property"),
			},
		},
		{
			Name:    "output",
			Type:    model.ResourceProperty_STRUCT,
			TypeRef: util.Pointer("Property"),
		},
		special.AnnotationsProperty,
	},
	Indexes: []*model.ResourceIndex{
		{
			Properties: []*model.ResourceIndexProperty{
				{
					Name: "resource",
				},
				{
					Name: "name",
				},
			},
			Unique: true,
		},
	},
	Annotations: map[string]string{
		annotations.EnableAudit:     annotations.Enabled,
		annotations.RestApiDisabled: annotations.Enabled,
		annotations.OpenApiGroup:    OpenApiMeta,
	},
}
View Source
var ResourcePropertyProperties = []*model.ResourceProperty{
	{
		Name:  "name",
		Title: util.Pointer("Name"),
		Description: util.Pointer(`The name of the property. 
Name is the main parameter of property, it is used to identify the property. It is also used to name record properties. 
For example {"title": "Lord of the Rings"} And there "title" is a property, and it is defined by name "title", in its Resource 
		`),
		Type:         model.ResourceProperty_STRING,
		Length:       256,
		ExampleValue: structpb.NewStringValue("title"),
		Required:     false,
	},
	{
		Name:        "type",
		Title:       util.Pointer("Type"),
		Description: util.Pointer(`The type of the property. Property Data Types can be one of it. Types can be written with all capital letters.`),
		Type:        model.ResourceProperty_ENUM,
		EnumValues: []string{
			"BOOL",
			"STRING",
			"FLOAT32",
			"FLOAT64",
			"INT32",
			"INT64",
			"BYTES",
			"UUID",
			"DATE",
			"TIME",
			"TIMESTAMP",
			"OBJECT",
			"MAP",
			"LIST",
			"REFERENCE",
			"ENUM",
			"STRUCT",
		},
		ExampleValue: structpb.NewStringValue("STRING"),
		Required:     true,
	},
	{
		Name:  "typeRef",
		Title: util.Pointer("Type Reference"),
		Description: util.Pointer(`The type reference of the property. It is only used for STRUCT type. 
When you used STRUCT type, you need to define your type inside types of resource and then you can use its name as typeRef.`),
		Type:         model.ResourceProperty_STRING,
		Length:       256,
		ExampleValue: structpb.NewStringValue("BookPublishingDetails"),
		Required:     false,
	},
	{
		Name:  "primary",
		Title: util.Pointer("Primary"),
		Description: util.Pointer(`The primary property of the resource. It is used to identify the resource. When it is not supplied, an id property is automatically created.
Normally primary property should not be provided. It is only used for special cases. If provided, it can break some functionalities of system. 
If Primary is provided, it should be a single property. It can not be a list or map.
If Primary is provided, internal id property will not be created.
`),
		Type:     model.ResourceProperty_BOOL,
		Required: true,

		DefaultValue: structpb.NewBoolValue(false),
	},
	{
		Name:  "required",
		Title: util.Pointer("Required"),
		Description: util.Pointer(`This property indicates that whether or not given property is required.
When creating/updating records, if required property is not and defaultValue is given in property, the system will allow request but will use default value instead.
(In all cases if default value is provided it will be used in case of property absence)
`),
		Type:     model.ResourceProperty_BOOL,
		Required: true,

		DefaultValue: structpb.NewBoolValue(false),
	},
	{
		Name:  "unique",
		Title: util.Pointer("Unique"),
		Description: util.Pointer(`This property indicates that whether or not given property is unique.
Unique property is only working for single property, for combination of properties to become unique, you can use indexes with unique flag 
`),
		Type:     model.ResourceProperty_BOOL,
		Required: true,

		DefaultValue: structpb.NewBoolValue(false),
	},
	{
		Name:        "immutable",
		Title:       util.Pointer("Immutable"),
		Description: util.Pointer("This property indicates that whether or not given property is immutable. Immutable properties can not be updated."),
		Type:        model.ResourceProperty_BOOL,
		Required:    true,

		DefaultValue: structpb.NewBoolValue(false),
	},
	{
		Name:         "length",
		Title:        util.Pointer("Length"),
		Description:  util.Pointer("This property indicates the length of the property. It is only used for STRING type."),
		Type:         model.ResourceProperty_INT32,
		Required:     true,
		ExampleValue: structpb.NewNumberValue(256),
		DefaultValue: structpb.NewNumberValue(256),
	},
	{
		Name:        "item",
		Title:       util.Pointer("Item"),
		Description: util.Pointer(`This property indicates the item type of the property. It is only used for LIST and MAP types.`),
		Type:        model.ResourceProperty_STRUCT,
		Required:    false,
		ExampleValue: structpb.NewStructValue(&structpb.Struct{
			Fields: map[string]*structpb.Value{
				"type": structpb.NewStringValue("STRING"),
			},
		}),
		TypeRef: util.Pointer("Property"),
	},
	{
		Name:  "reference",
		Title: util.Pointer("Reference"),
		Description: util.Pointer(`This property indicates the reference type of the property. It is only used for REFERENCE type.
When you use REFERENCE type, you need to provide reference details.
Reference details is used to locate referenced resource
When providing reference details, you need to provide namespace and resource name of the referenced resource.
If you don't provide namespace, it will be assumed as the same namespace with the resource.
`),
		Type: model.ResourceProperty_STRUCT,
		ExampleValue: structpb.NewStructValue(&structpb.Struct{
			Fields: map[string]*structpb.Value{
				"resource": structpb.NewStructValue(&structpb.Struct{
					Fields: map[string]*structpb.Value{
						"namespace": structpb.NewStringValue("default"),
						"resource":  structpb.NewStringValue("Book"),
					},
				}),
			},
		}),
		TypeRef: util.Pointer("Reference"),
	},
	{
		Name:  "defaultValue",
		Title: util.Pointer("Default Value"),
		Description: util.Pointer(`This property indicates the default value of the property. 
It is used when creating/updating records and property is not provided.
`),
		Type:         model.ResourceProperty_OBJECT,
		ExampleValue: structpb.NewStringValue("Lord of the Rings"),
		Required:     false,
	},
	{
		Name:        "enumValues",
		Title:       util.Pointer("Enum Values"),
		Description: util.Pointer(`This property is only used with ENUM type. This property indicates the enum values of the property.`),
		Type:        model.ResourceProperty_LIST,
		Item: &model.ResourceProperty{
			Type: model.ResourceProperty_STRING,
		},
		ExampleValue: structpb.NewListValue(&structpb.ListValue{
			Values: []*structpb.Value{
				structpb.NewStringValue("UNKNOWN"),
				structpb.NewStringValue("ASC"),
				structpb.NewStringValue("DESC"),
			},
		}),
		Required: false,
	},
	{
		Name:         "exampleValue",
		Title:        util.Pointer("Example Value"),
		Description:  util.Pointer(`This property indicates the example value of the property.`),
		Type:         model.ResourceProperty_OBJECT,
		ExampleValue: structpb.NewStringValue(`no-book-name`),
		Required:     false,
	},
	{
		Name:         "title",
		Title:        util.Pointer("Title"),
		Description:  util.Pointer(`This property indicates the title of the property. It is used to have meaningful names for the properties.`),
		Type:         model.ResourceProperty_STRING,
		Length:       256,
		ExampleValue: structpb.NewStringValue(`Book Title`),
		Required:     false,
	},
	{
		Name:         "description",
		Title:        util.Pointer("Description"),
		Description:  util.Pointer(`This property indicates the description of the property. It is used to have meaningful description for the properties.`),
		Type:         model.ResourceProperty_STRING,
		Length:       256,
		ExampleValue: structpb.NewStringValue(`Book Title is a property of Book Resource. It represents the title of the book.`),
		Required:     false,
	},
	special.AnnotationsProperty,
}
View Source
var ResourceResource = &model.Resource{
	Name:        "Resource",
	Namespace:   "system",
	Title:       util.Pointer("Resource"),
	Description: util.Pointer("Resource is a top level resource that represents a model and API in the system"),
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "resource",
	},
	Types: []*model.ResourceSubType{
		PropertyType,
		SubTypeType,
		special.AuditDataSubType,
		{
			Name: "IndexProperty",
			Properties: []*model.ResourceProperty{
				{
					Name:     "name",
					Type:     model.ResourceProperty_STRING,
					Required: true,
				},
				{
					Name:     "order",
					Type:     model.ResourceProperty_ENUM,
					Required: false,
					EnumValues: []string{
						"UNKNOWN", "ASC", "DESC",
					},
					DefaultValue: structpb.NewStringValue("ASC"),
				},
			},
		},
		{
			Name: "Index",
			Properties: []*model.ResourceProperty{
				{
					Name: "properties",
					Type: model.ResourceProperty_LIST,
					Item: &model.ResourceProperty{
						Type:    model.ResourceProperty_STRUCT,
						TypeRef: util.Pointer("IndexProperty"),
					},
				},
				{
					Name:     "indexType",
					Type:     model.ResourceProperty_ENUM,
					Required: false,
					EnumValues: []string{
						"BTREE", "HASH",
					},
					DefaultValue: structpb.NewStringValue("BTREE"),
				},
				{
					Name:     "unique",
					Type:     model.ResourceProperty_BOOL,
					Required: false,
				},
				special.AnnotationsProperty,
			},
		},
		ReferenceType,
	},
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		special.AuditProperty,
		{
			Name:         "name",
			Title:        util.Pointer("Name"),
			Description:  util.Pointer("The name of the resource. Name is the main parameter of resource, it is used to identify the resource. It is also used to name API endpoints."),
			Type:         model.ResourceProperty_STRING,
			Length:       256,
			Required:     true,
			Unique:       false,
			ExampleValue: structpb.NewStringValue("Book"),
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:        "namespace",
			Title:       util.Pointer("Namespace"),
			Description: util.Pointer("The namespace of the resource. Namespace is used to group resources. It is also used to name API endpoints together with Resource. "),
			Type:        model.ResourceProperty_REFERENCE,
			Required:    true,
			Reference: &model.Reference{
				Resource:  NamespaceResource.Name,
				Namespace: NamespaceResource.Namespace,
				Cascade:   false,
			},
			ExampleValue: structpb.NewStructValue(&structpb.Struct{
				Fields: map[string]*structpb.Value{
					"name": structpb.NewStringValue("system"),
				},
			}),
		},
		{
			Name:  "virtual",
			Title: util.Pointer("Virtual"),
			Description: util.Pointer(`This property indicates that whether or not given resource is virtual. 
Virtual resources are not stored in database. They are created on the fly.
Virtual resources are used to prepare bind them to extensions or nano codes, etc. without touching to database.
`),
			Type:     model.ResourceProperty_BOOL,
			Required: true,

			DefaultValue: structpb.NewBoolValue(false),
		},
		{
			Name:        "properties",
			Title:       util.Pointer("Properties"),
			Description: util.Pointer(`This property indicates the properties of the resource.`),
			Type:        model.ResourceProperty_LIST,
			Required:    true,
			Item: &model.ResourceProperty{
				Type:    model.ResourceProperty_STRUCT,
				TypeRef: util.Pointer("Property"),
			},
			ExampleValue: structpb.NewListValue(&structpb.ListValue{
				Values: []*structpb.Value{
					structpb.NewStructValue(&structpb.Struct{
						Fields: map[string]*structpb.Value{
							"name": structpb.NewStringValue("title"),
							"type": structpb.NewStringValue("name"),
						},
					}),
					structpb.NewStructValue(&structpb.Struct{
						Fields: map[string]*structpb.Value{
							"name": structpb.NewStringValue("type"),
							"type": structpb.NewStringValue("STRING"),
						},
					}),
				},
			}),
		},
		{
			Name:  "indexes",
			Title: util.Pointer("Indexes"),
			Description: util.Pointer(`This property indicates the indexes of the resource.
Indexes are used to speed up the queries. Indexes are used to define complex unique constraints.
`),
			Type:     model.ResourceProperty_LIST,
			Required: false,
			Item: &model.ResourceProperty{
				Type:    model.ResourceProperty_STRUCT,
				TypeRef: util.Pointer("Index"),
			},
		},
		{
			Name:  "types",
			Title: util.Pointer("Types"),
			Description: util.Pointer(`This property indicates the types of the resource.
This is used to hav sub types, which will be used by other properties which has type STRUCT.
`),
			Type:     model.ResourceProperty_LIST,
			Required: false,
			Item: &model.ResourceProperty{
				Type:    model.ResourceProperty_STRUCT,
				TypeRef: util.Pointer("SubType"),
			},
		},
		{
			Name:         "immutable",
			Title:        util.Pointer("Immutable"),
			Description:  util.Pointer("This property indicates that whether or not given resource is immutable. Immutable resources can not be updated or deleted."),
			Type:         model.ResourceProperty_BOOL,
			Required:     true,
			DefaultValue: structpb.NewBoolValue(false),
		},
		{
			Name:  "abstract",
			Title: util.Pointer("Abstract"),
			Description: util.Pointer(`This property indicates that whether or not given resource is abstract.
Abstract resources are not stored in database. No record related operation is allowed in abstract resources.
Abstract resources are mostly used for code generation (for abstract types, etc.)
`),
			Type:     model.ResourceProperty_BOOL,
			Required: true,

			DefaultValue: structpb.NewBoolValue(false),
		},
		{
			Name:        "checkReferences",
			Title:       util.Pointer("Check References"),
			Description: util.Pointer(`This property indicates that whether or not check references is enabled. Check references resources are used to check references to other resources. It is acting if enabled only in create/update operations`),
			Type:        model.ResourceProperty_BOOL,
			Required:    true,

			DefaultValue: structpb.NewBoolValue(false),
		},
		{
			Name:  "dataSource",
			Title: util.Pointer("Data Source"),
			Description: util.Pointer(`This property indicates the data source of the resource.
Data source is used to store the records of the resource.
Each resource can have only one data source. But data source can be different from resource to resource.
Updating data source of a resource is not migrating any data.
DataSource property is used for non-virtual resources.
If DataSource is not provided, default DataSource will be used
`),
			Type:     model.ResourceProperty_REFERENCE,
			Required: false,
			Reference: &model.Reference{
				Resource:  DataSourceResource.Name,
				Namespace: DataSourceResource.Namespace,
				Cascade:   false,
			},
		},
		{
			Name:         "entity",
			Title:        util.Pointer("Entity"),
			Description:  util.Pointer(`This property indicates the entity of the resource. By entity, table name is considered for relational databases`),
			Type:         model.ResourceProperty_STRING,
			Length:       256,
			Required:     false,
			ExampleValue: structpb.NewStringValue("book"),
		},
		{
			Name:         "catalog",
			Title:        util.Pointer("Catalog"),
			Description:  util.Pointer(`This property indicates the catalog of the resource. By catalog, schema name is considered for relational databases.`),
			Type:         model.ResourceProperty_STRING,
			Length:       256,
			Required:     false,
			ExampleValue: structpb.NewStringValue("public"),
		},
		{
			Name:         "title",
			Title:        util.Pointer("Title"),
			Description:  util.Pointer(`This property indicates the title of the resource. It is used to have meaningful names for the resources.`),
			Type:         model.ResourceProperty_STRING,
			Length:       256,
			Required:     false,
			ExampleValue: structpb.NewStringValue(`Book`),
		},
		{
			Name:         "description",
			Title:        util.Pointer("Description"),
			Description:  util.Pointer(`This property indicates the description of the resource. It is used to have meaningful description for the resources.`),
			Type:         model.ResourceProperty_STRING,
			Length:       256,
			Required:     false,
			ExampleValue: structpb.NewStringValue(`Book is a resource in the system. It represents a book in the system.`),
		},
		special.AnnotationsProperty,
	},
	Indexes: []*model.ResourceIndex{
		{
			Properties: []*model.ResourceIndexProperty{
				{
					Name: "namespace",
				},
				{
					Name: "name",
				},
			},
			Unique: true,
		},
	},
	Annotations: map[string]string{
		annotations.EnableAudit:     annotations.Enabled,
		annotations.RestApiDisabled: annotations.Enabled,
		annotations.OpenApiGroup:    OpenApiMeta,
		annotations.OpenApiRestPath: "resources",
	},
}
View Source
var RoleResource = &model.Resource{
	Name:        "Role",
	Title:       util.Pointer("Role"),
	Description: util.Pointer("Role is a resource that defines the access control model. It is used to give permissions to users in a grouped way"),
	Namespace:   "system",
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "role",
	},
	Types: []*model.ResourceSubType{
		special.AuditDataSubType,
	},
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		special.AuditProperty,
		{
			Name:        "name",
			Title:       util.Pointer("Name"),
			Description: util.Pointer(`The name of the role`),
			Type:        model.ResourceProperty_STRING,
			Length:      256,
			Required:    true,
			Unique:      true,
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:        "permissions",
			Description: util.Pointer(`The permissions of the role. It is used to define the access control rules for resources for roles. When you set permissions it is automatically created though Permission Resource. No need to manage it manually`),
			Type:        model.ResourceProperty_LIST,
			Item: &model.ResourceProperty{
				Type: model.ResourceProperty_REFERENCE,
				Reference: &model.Reference{
					Namespace: "system",
					Resource:  "Permission",
				},
				BackReference: &model.BackReference{
					Property: "role",
				},
			},
			Required: false,
		},
		{
			Name:        "details",
			Title:       util.Pointer("Details"),
			Description: util.Pointer(`The details of the user. It is used to store additional information about the user.`),
			Type:        model.ResourceProperty_OBJECT,
		},
	},
	Annotations: map[string]string{
		annotations.EnableAudit:  annotations.Enabled,
		annotations.OpenApiGroup: OpenApiMeta,
	},
}
View Source
var SubTypeType = &model.ResourceSubType{
	Name:        "SubType",
	Title:       "Sub Type",
	Description: "Sub Type is a type that represents a sub type of a resource. It is mostly used by STRUCT type to define the properties of the struct. ",
	Annotations: map[string]string{
		annotations.CommonType: annotations.Enabled,
	},
	Properties: []*model.ResourceProperty{
		{
			Name:         "name",
			Title:        util.Pointer("Name"),
			Description:  util.Pointer("The name of the sub type. "),
			Type:         model.ResourceProperty_STRING,
			ExampleValue: structpb.NewStringValue("Book"),
			Required:     true,
		},
		{
			Name:         "title",
			Title:        util.Pointer("Title"),
			Description:  util.Pointer("The title of the sub type. It is used to have meaningful names for the sub types."),
			Type:         model.ResourceProperty_STRING,
			Length:       256,
			ExampleValue: structpb.NewStringValue("Book"),
			Required:     false,
		},
		{
			Name:         "description",
			Title:        util.Pointer("Description"),
			Description:  util.Pointer("The description of the sub type. It is used to have meaningful description for the sub types. "),
			Type:         model.ResourceProperty_STRING,
			Length:       256,
			ExampleValue: structpb.NewStringValue("Book is a sub type of Resource. It represents a book in the system. "),
			Required:     false,
		},
		{
			Name:        "properties",
			Title:       util.Pointer("Properties"),
			Description: util.Pointer("The properties of the sub type. It is used to define the properties of the sub type. "),
			Type:        model.ResourceProperty_LIST,
			Required:    true,
			Item: &model.ResourceProperty{
				Type:    model.ResourceProperty_STRUCT,
				TypeRef: util.Pointer("Property"),
			},
			ExampleValue: structpb.NewListValue(&structpb.ListValue{
				Values: []*structpb.Value{
					structpb.NewStructValue(&structpb.Struct{
						Fields: map[string]*structpb.Value{
							"name": structpb.NewStringValue("title"),
							"type": structpb.NewStringValue("STRING"),
						},
					}),
				},
			}),
		},
	},
}
View Source
var UserResource = &model.Resource{
	Name:        "User",
	Title:       util.Pointer("User"),
	Description: util.Pointer("User is a resource that defines the access control model. It is used to authenticate and authorize users."),
	Namespace:   "system",
	SourceConfig: &model.ResourceSourceConfig{
		DataSource: "system",
		Entity:     "user",
	},
	Types: []*model.ResourceSubType{
		special.AuditDataSubType,
	},
	Properties: []*model.ResourceProperty{
		special.IdProperty,
		special.VersionProperty,
		special.AuditProperty,
		{
			Name:     "username",
			Title:    util.Pointer("Username"),
			Type:     model.ResourceProperty_STRING,
			Length:   256,
			Required: true,
			Unique:   true,
			Annotations: map[string]string{
				annotations.IsHclLabel: annotations.Enabled,
			},
		},
		{
			Name:     "password",
			Title:    util.Pointer("Password"),
			Type:     model.ResourceProperty_STRING,
			Length:   256,
			Required: false,
		},
		{
			Name:  "roles",
			Title: util.Pointer("Roles"),
			Type:  model.ResourceProperty_LIST,
			Item: &model.ResourceProperty{
				Type: model.ResourceProperty_REFERENCE,
				Reference: &model.Reference{
					Namespace: RoleResource.Namespace,
					Resource:  RoleResource.Name,
				},
			},
		},
		{
			Name:        "permissions",
			Title:       util.Pointer("Permissions"),
			Description: util.Pointer(`The permissions of the user. It is used to define the access control rules for resources for users. When you set permissions it is automatically created though Permission Resource. No need to manage it manually`),
			Type:        model.ResourceProperty_LIST,
			Item: &model.ResourceProperty{
				Type: model.ResourceProperty_REFERENCE,
				Reference: &model.Reference{
					Namespace: "system",
					Resource:  "Permission",
				},
				BackReference: &model.BackReference{
					Property: "user",
				},
			},
			Required: false,
		},
		{
			Name:        "details",
			Title:       util.Pointer("Details"),
			Description: util.Pointer(`The details of the user. It is used to store additional information about the user.`),
			Type:        model.ResourceProperty_OBJECT,
		},
	},
	Annotations: map[string]string{
		annotations.EnableAudit:  annotations.Enabled,
		annotations.OpenApiGroup: OpenApiMeta,
	},
}

Functions

func GetAllSystemResources

func GetAllSystemResources() []*model.Resource

func GetSystemResourceType

func GetSystemResourceType(resource *model.Resource) proto.Message

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL