// NewDocument creates an object of type Document if possible, returning an error if not.
16202
func NewDocument(in interface{}, context *compiler.Context) (*Document, error) {
	errors := make([]error, 0)
	x := &Document{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		requiredKeys := []string{"info", "paths", "swagger"}
		missingKeys := compiler.MissingKeysInMap(m, requiredKeys)
		if len(missingKeys) > 0 {
			message := fmt.Sprintf("is missing required %s: %+v", compiler.PluralProperties(len(missingKeys)), strings.Join(missingKeys, ", "))
			errors = append(errors, compiler.NewError(context, message))
		}
		allowedKeys := []string{"basePath", "consumes", "definitions", "externalDocs", "host", "info", "parameters", "paths", "produces", "responses", "schemes", "security", "securityDefinitions", "swagger", "tags"}
		allowedPatterns := []*regexp.Regexp{pattern0}
		invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
		if len(invalidKeys) > 0 {
			message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
			errors = append(errors, compiler.NewError(context, message))
		}
		// string swagger = 1;
		v1 := compiler.MapValueForKey(m, "swagger")
		if v1 != nil {
			x.Swagger, ok = v1.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for swagger: %+v (%T)", v1, v1)
				errors = append(errors, compiler.NewError(context, message))
			}
			// check for valid enum values
			// [2.0]
			if ok && !compiler.StringArrayContainsValue([]string{"2.0"}, x.Swagger) {
				message := fmt.Sprintf("has unexpected value for swagger: %+v (%T)", v1, v1)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// Info info = 2;
		v2 := compiler.MapValueForKey(m, "info")
		if v2 != nil {
			var err error
			x.Info, err = NewInfo(v2, compiler.NewContext("info", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// string host = 3;
		v3 := compiler.MapValueForKey(m, "host")
		if v3 != nil {
			x.Host, ok = v3.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for host: %+v (%T)", v3, v3)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// string base_path = 4;
		v4 := compiler.MapValueForKey(m, "basePath")
		if v4 != nil {
			x.BasePath, ok = v4.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for basePath: %+v (%T)", v4, v4)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// repeated string schemes = 5;
		v5 := compiler.MapValueForKey(m, "schemes")
		if v5 != nil {
			v, ok := v5.([]interface{})
			if ok {
				x.Schemes = compiler.ConvertInterfaceArrayToStringArray(v)
			} else {
				message := fmt.Sprintf("has unexpected value for schemes: %+v (%T)", v5, v5)
				errors = append(errors, compiler.NewError(context, message))
			}
			// check for valid enum values
			// [http https ws wss]
			if ok && !compiler.StringArrayContainsValues([]string{"http", "https", "ws", "wss"}, x.Schemes) {
				message := fmt.Sprintf("has unexpected value for schemes: %+v", v5)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// repeated string consumes = 6;
		v6 := compiler.MapValueForKey(m, "consumes")
		if v6 != nil {
			v, ok := v6.([]interface{})
			if ok {
				x.Consumes = compiler.ConvertInterfaceArrayToStringArray(v)
			} else {
				message := fmt.Sprintf("has unexpected value for consumes: %+v (%T)", v6, v6)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// repeated string produces = 7;
		v7 := compiler.MapValueForKey(m, "produces")
		if v7 != nil {
			v, ok := v7.([]interface{})
			if ok {
				x.Produces = compiler.ConvertInterfaceArrayToStringArray(v)
			} else {
				message := fmt.Sprintf("has unexpected value for produces: %+v (%T)", v7, v7)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// Paths paths = 8;
		v8 := compiler.MapValueForKey(m, "paths")
		if v8 != nil {
			var err error
			x.Paths, err = NewPaths(v8, compiler.NewContext("paths", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// Definitions definitions = 9;
		v9 := compiler.MapValueForKey(m, "definitions")
		if v9 != nil {
			var err error
			x.Definitions, err = NewDefinitions(v9, compiler.NewContext("definitions", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// ParameterDefinitions parameters = 10;
		v10 := compiler.MapValueForKey(m, "parameters")
		if v10 != nil {
			var err error
			x.Parameters, err = NewParameterDefinitions(v10, compiler.NewContext("parameters", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// ResponseDefinitions responses = 11;
		v11 := compiler.MapValueForKey(m, "responses")
		if v11 != nil {
			var err error
			x.Responses, err = NewResponseDefinitions(v11, compiler.NewContext("responses", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// repeated SecurityRequirement security = 12;
		v12 := compiler.MapValueForKey(m, "security")
		if v12 != nil {
			// repeated SecurityRequirement
			x.Security = make([]*SecurityRequirement, 0)
			a, ok := v12.([]interface{})
			if ok {
				for _, item := range a {
					y, err := NewSecurityRequirement(item, compiler.NewContext("security", context))
					if err != nil {
						errors = append(errors, err)
					}
					x.Security = append(x.Security, y)
				}
			}
		}
		// SecurityDefinitions security_definitions = 13;
		v13 := compiler.MapValueForKey(m, "securityDefinitions")
		if v13 != nil {
			var err error
			x.SecurityDefinitions, err = NewSecurityDefinitions(v13, compiler.NewContext("securityDefinitions", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// repeated Tag tags = 14;
		v14 := compiler.MapValueForKey(m, "tags")
		if v14 != nil {
			// repeated Tag
			x.Tags = make([]*Tag, 0)
			a, ok := v14.([]interface{})
			if ok {
				for _, item := range a {
					y, err := NewTag(item, compiler.NewContext("tags", context))
					if err != nil {
						errors = append(errors, err)
					}
					x.Tags = append(x.Tags, y)
				}
			}
		}
		// ExternalDocs external_docs = 15;
		v15 := compiler.MapValueForKey(m, "externalDocs")
		if v15 != nil {
			var err error
			x.ExternalDocs, err = NewExternalDocs(v15, compiler.NewContext("externalDocs", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// repeated NamedAny vendor_extension = 16;
		// MAP: Any ^x-
		x.VendorExtension = make([]*NamedAny, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				if strings.HasPrefix(k, "x-") {
					pair := &NamedAny{}
					pair.Name = k
					result := &Any{}
					handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
					if handled {
						if err != nil {
							errors = append(errors, err)
						} else {
							bytes, _ := yaml.Marshal(v)
							result.Yaml = string(bytes)
							result.Value = resultFromExt
							pair.Value = result
						}
					} else {
						pair.Value, err = NewAny(v, compiler.NewContext(k, context))
						if err != nil {
							errors = append(errors, err)
						}
					}
					x.VendorExtension = append(x.VendorExtension, pair)
				}
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
835920
func NewDocumentBackend(b *APIBackend) *DocumentBackend {
	return &DocumentBackend{
		Logger:          b.Logger.With(zap.String("handler", "document")),
		DocumentService: b.DocumentService,
		LabelService:    b.LabelService,
	}
}
35613
func New(doc *goquery.Document) *GopenGraph {
	mg := new(GopenGraph)
	mg.MandatoryAttrs = []string{"og:title", "og:type", "og:image", "og:url"}
	mg.PopulateOgTags(doc)
	mg.PopulateAttrs(doc)
	mg.Url = doc.Url.String()

	return mg
}
513016
func NewDoc(content interface{}) *Context {
    c := &Context {
        Names: make(map[string]int),
    }

    switch t := content.(type) {
    case string:
        if t == "" {
            c.List = nil
        } else {
            c.List = [][]byte{[]byte(t)}
        }
    case []byte:
        if t == nil {
            c.List = nil
        } else {
            c.List = [][]byte{t}
        }
    default: 
        // panic?
        // panic("invalid doc")
    }

    return c
}
1060073
func (doc *Document) Create(data []byte) error {
	docResp, err := doc.createOrUpdate(data)

	if err != nil {
		return err
	}

	doc.Id = docResp.Id
	doc.Rev = docResp.Rev
	return err
}
153339
func NewDocumentUpload(chatID int64, file interface{}) DocumentConfig {
	return DocumentConfig{
		BaseFile: BaseFile{
			BaseChat:    BaseChat{ChatID: chatID},
			File:        file,
			UseExisting: false,
		},
	}
}
1063709
func (s *AnalyzeDocumentInput) SetDocument(v *Document) *AnalyzeDocumentInput {
	s.Document = v
	return s
}
952736
func (c *edgeCollection) ReadDocument(ctx context.Context, key string, result interface{}) (DocumentMeta, error) {
	meta, _, err := c.readDocument(ctx, key, result)
	if err != nil {
		return DocumentMeta{}, WithStack(err)
	}
	return meta, nil
}
1281373
func newActionDoc(mb modelBackend, receiverTag names.Tag, actionName string, parameters map[string]interface{}) (actionDoc, actionNotificationDoc, error) {
	prefix := ensureActionMarker(receiverTag.Id())
	actionId, err := NewUUID()
	if err != nil {
		return actionDoc{}, actionNotificationDoc{}, err
	}
	actionLogger.Debugf("newActionDoc name: '%s', receiver: '%s', actionId: '%s'", actionName, receiverTag, actionId)
	modelUUID := mb.modelUUID()
	return actionDoc{
			DocId:      mb.docID(actionId.String()),
			ModelUUID:  modelUUID,
			Receiver:   receiverTag.Id(),
			Name:       actionName,
			Parameters: parameters,
			Enqueued:   mb.nowToTheSecond(),
			Status:     ActionPending,
		}, actionNotificationDoc{
			DocId:     mb.docID(prefix + actionId.String()),
			ModelUUID: modelUUID,
			Receiver:  receiverTag.Id(),
			ActionID:  actionId.String(),
		}, nil
}
1352310
func (s *CreateTrafficPolicyVersionInput) SetDocument(v string) *CreateTrafficPolicyVersionInput {
	s.Document = &v
	return s
}
97477
func (doc *Document) Update(newBody []byte) error {
	oldBody, err := doc.Exists()

	if err == nil {
		newData, err := doc.updateDocument(oldBody, newBody)
		if err != nil {
			return errors.New("Update document error " + err.Error())
		}
		_, err = doc.createOrUpdate(newData)
	}
	return err
}
1348748
func CreateElement(tag string) *js.Object {
	doc := GetDocument()
	if doc == nil || doc == js.Undefined {
		return nil
	}
	return doc.Call("createElement", tag)
}
686123
func NewDocumentShare(chatID int64, fileID string) DocumentConfig {
	return DocumentConfig{
		BaseFile: BaseFile{
			BaseChat:    BaseChat{ChatID: chatID},
			FileID:      fileID,
			UseExisting: true,
		},
	}
}
786509
func NewObject(Expr node.Node) *Object {
	return &Object{
		FreeFloating: nil,
		Expr:         Expr,
	}
}
727234
func NewDocumentHandler(b *DocumentBackend) *DocumentHandler {
	h := &DocumentHandler{
		Router: NewRouter(),
		Logger: b.Logger,

		DocumentService: b.DocumentService,
		LabelService:    b.LabelService,
	}

	h.HandlerFunc("POST", documentsPath, h.handlePostDocument)
	h.HandlerFunc("GET", documentsPath, h.handleGetDocuments)
	h.HandlerFunc("GET", documentPath, h.handleGetDocument)
	h.HandlerFunc("PUT", documentPath, h.handlePutDocument)
	h.HandlerFunc("DELETE", documentPath, h.handleDeleteDocument)

	h.HandlerFunc("GET", documentLabelsPath, h.handleGetDocumentLabel)
	h.HandlerFunc("POST", documentLabelsPath, h.handlePostDocumentLabel)
	h.HandlerFunc("DELETE", documentLabelsIDPath, h.handleDeleteDocumentLabel)

	return h
}
468105
func NewDocument(p unsafe.Pointer, contentLen int, inEncoding, outEncoding []byte) (doc *HtmlDocument) {
	doc = &HtmlDocument{}
	doc.XmlDocument = xml.NewDocument(p, contentLen, inEncoding, outEncoding)
	doc.Me = doc
	node := doc.Node.(*xml.XmlNode)
	node.Document = doc
	//runtime.SetFinalizer(doc, (*HtmlDocument).Free)
	return
}
978803
func New(format string, args ...interface{}) error {
	return annotate(errors.New(fmt.Sprintf(format, args...)), "")
}