// CreateDictionaryItem creates a new Fastly dictionary item.
973144
func (c *Client) CreateDictionaryItem(i *CreateDictionaryItemInput) (*DictionaryItem, error) {
	if i.Service == "" {
		return nil, ErrMissingService
	}

	if i.Dictionary == "" {
		return nil, ErrMissingDictionary
	}

	path := fmt.Sprintf("/service/%s/dictionary/%s/item", i.Service, i.Dictionary)
	resp, err := c.PostForm(path, i, nil)
	if err != nil {
		return nil, err
	}

	var b *DictionaryItem
	if err := decodeJSON(&b, resp.Body); err != nil {
		return nil, err
	}
	return b, nil
}
915591
func dict_popitem(fnname string, recv_ Value, args Tuple, kwargs []Tuple) (Value, error) {
	if err := UnpackPositionalArgs(fnname, args, kwargs, 0); err != nil {
		return nil, err
	}
	recv := recv_.(*Dict)
	k, ok := recv.ht.first()
	if !ok {
		return nil, fmt.Errorf("popitem: empty dict")
	}
	v, _, err := recv.Delete(k)
	if err != nil {
		return nil, err // dict is frozen
	}
	return Tuple{k, v}, nil
}
10660
func CreateDeviceQueueItem(db sqlx.Queryer, qi *DeviceQueueItem) error {
	if err := qi.Validate(); err != nil {
		return err
	}

	now := time.Now()
	qi.CreatedAt = now
	qi.UpdatedAt = now

	err := sqlx.Get(db, &qi.ID, `
        insert into device_queue (
            created_at,
            updated_at,
			dev_addr,
            dev_eui,
            frm_payload,
            f_cnt,
            f_port,
            confirmed,
            emit_at_time_since_gps_epoch,
            is_pending,
            timeout_after
        ) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
        returning id`,
		qi.CreatedAt,
		qi.UpdatedAt,
		qi.DevAddr[:],
		qi.DevEUI[:],
		qi.FRMPayload,
		qi.FCnt,
		qi.FPort,
		qi.Confirmed,
		qi.EmitAtTimeSinceGPSEpoch,
		qi.IsPending,
		qi.TimeoutAfter,
	)
	if err != nil {
		return handlePSQLError(err, "insert error")
	}

	log.WithFields(log.Fields{
		"dev_eui": qi.DevEUI,
		"f_cnt":   qi.FCnt,
	}).Info("device-queue item created")

	return nil
}
290191
func blocklistItem(name string) string {
	base := filepath.Base(name)

	for _, p := range prefixBlocklist {
		if strings.HasPrefix(base, p) {
			return p
		}
	}

	return ""
}
1284009
func NewPathItem(in interface{}, context *compiler.Context) (*PathItem, error) {
	errors := make([]error, 0)
	x := &PathItem{}
	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 {
		allowedKeys := []string{"$ref", "delete", "description", "get", "head", "options", "parameters", "patch", "post", "put", "servers", "summary", "trace"}
		allowedPatterns := []*regexp.Regexp{pattern1}
		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 _ref = 1;
		v1 := compiler.MapValueForKey(m, "$ref")
		if v1 != nil {
			x.XRef, ok = v1.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for $ref: %+v (%T)", v1, v1)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// string summary = 2;
		v2 := compiler.MapValueForKey(m, "summary")
		if v2 != nil {
			x.Summary, ok = v2.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for summary: %+v (%T)", v2, v2)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// string description = 3;
		v3 := compiler.MapValueForKey(m, "description")
		if v3 != nil {
			x.Description, ok = v3.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v3, v3)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// Operation get = 4;
		v4 := compiler.MapValueForKey(m, "get")
		if v4 != nil {
			var err error
			x.Get, err = NewOperation(v4, compiler.NewContext("get", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// Operation put = 5;
		v5 := compiler.MapValueForKey(m, "put")
		if v5 != nil {
			var err error
			x.Put, err = NewOperation(v5, compiler.NewContext("put", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// Operation post = 6;
		v6 := compiler.MapValueForKey(m, "post")
		if v6 != nil {
			var err error
			x.Post, err = NewOperation(v6, compiler.NewContext("post", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// Operation delete = 7;
		v7 := compiler.MapValueForKey(m, "delete")
		if v7 != nil {
			var err error
			x.Delete, err = NewOperation(v7, compiler.NewContext("delete", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// Operation options = 8;
		v8 := compiler.MapValueForKey(m, "options")
		if v8 != nil {
			var err error
			x.Options, err = NewOperation(v8, compiler.NewContext("options", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// Operation head = 9;
		v9 := compiler.MapValueForKey(m, "head")
		if v9 != nil {
			var err error
			x.Head, err = NewOperation(v9, compiler.NewContext("head", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// Operation patch = 10;
		v10 := compiler.MapValueForKey(m, "patch")
		if v10 != nil {
			var err error
			x.Patch, err = NewOperation(v10, compiler.NewContext("patch", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// Operation trace = 11;
		v11 := compiler.MapValueForKey(m, "trace")
		if v11 != nil {
			var err error
			x.Trace, err = NewOperation(v11, compiler.NewContext("trace", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// repeated Server servers = 12;
		v12 := compiler.MapValueForKey(m, "servers")
		if v12 != nil {
			// repeated Server
			x.Servers = make([]*Server, 0)
			a, ok := v12.([]interface{})
			if ok {
				for _, item := range a {
					y, err := NewServer(item, compiler.NewContext("servers", context))
					if err != nil {
						errors = append(errors, err)
					}
					x.Servers = append(x.Servers, y)
				}
			}
		}
		// repeated ParameterOrReference parameters = 13;
		v13 := compiler.MapValueForKey(m, "parameters")
		if v13 != nil {
			// repeated ParameterOrReference
			x.Parameters = make([]*ParameterOrReference, 0)
			a, ok := v13.([]interface{})
			if ok {
				for _, item := range a {
					y, err := NewParameterOrReference(item, compiler.NewContext("parameters", context))
					if err != nil {
						errors = append(errors, err)
					}
					x.Parameters = append(x.Parameters, y)
				}
			}
		}
		// repeated NamedAny specification_extension = 14;
		// MAP: Any ^x-
		x.SpecificationExtension = 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.SpecificationExtension = append(x.SpecificationExtension, pair)
				}
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
370640
func (c *Cache) serializeItem(item *itemWithExp) ([]byte, error) {
	blob, err := c.Marshal(item.val)
	if err != nil {
		return nil, err
	}

	var deadline uint64
	if !item.exp.IsZero() {
		deadline = uint64(item.exp.Unix())
	}

	// <version_byte> + <uint64 deadline timestamp> + <blob>
	output := make([]byte, 9+len(blob))
	output[0] = formatVersionByte
	binary.LittleEndian.PutUint64(output[1:], deadline)
	copy(output[9:], blob)
	return output, nil
}
1288277
func (m *Microdata) addItem(item *Item) {
	m.Items = append(m.Items, item)
}
662109
func (s *EndpointsResponse) SetItem(v []*EndpointResponse) *EndpointsResponse {
	s.Item = v
	return s
}
1364292
func (c *Client) UpdateDictionary(i *UpdateDictionaryInput) (*Dictionary, error) {
	if i.Service == "" {
		return nil, ErrMissingService
	}

	if i.Version == 0 {
		return nil, ErrMissingVersion
	}

	if i.Name == "" {
		return nil, ErrMissingName
	}

	path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s", i.Service, i.Version, i.Name)
	resp, err := c.PutForm(path, i, nil)
	if err != nil {
		return nil, err
	}

	var b *Dictionary
	if err := decodeJSON(&b, resp.Body); err != nil {
		return nil, err
	}
	return b, nil
}
696149
func (bk *Bucket) PrefixItems(pre []byte) (items []Item, err error) {
	err = bk.db.View(func(tx *bolt.Tx) error {
		c := tx.Bucket(bk.Name).Cursor()
		var key, value []byte
		for k, v := c.Seek(pre); bytes.HasPrefix(k, pre); k, v = c.Next() {
			if v != nil {
				key = make([]byte, len(k))
				copy(key, k)
				value = make([]byte, len(v))
				copy(value, v)
				items = append(items, Item{key, value})
			}
		}
		return nil
	})
	return items, err
}
1011871
func (s *GetStagesOutput) SetItem(v []*Stage) *GetStagesOutput {
	s.Item = v
	return s
}
327439
func (menu *Menu) AddItem(commandID uint, label string) {
	command := Command{
		Method: "add_item",
		Args: CommandArguments{
			CommandID: commandID,
			Label:     label,
		},
	}
	menuItem := MenuItem{
		CommandID: commandID,
		Label:     label,
		Parent:    menu,
		Type:      "item",
	}
	menu.Items = append(menu.Items, &menuItem)

	menu.CallWhenReady(&command)
}
844299
func NewItemsItem(in interface{}, context *compiler.Context) (*ItemsItem, error) {
	errors := make([]error, 0)
	x := &ItemsItem{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value for item array: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		x.Schema = make([]*Schema, 0)
		y, err := NewSchema(m, compiler.NewContext("<array>", context))
		if err != nil {
			return nil, err
		}
		x.Schema = append(x.Schema, y)
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
291820
func (n *NetworkServerAPI) CreateDeviceQueueItem(ctx context.Context, req *ns.CreateDeviceQueueItemRequest) (*empty.Empty, error) {
	if req.Item == nil {
		return nil, grpc.Errorf(codes.InvalidArgument, "item must not be nil")
	}

	var devEUI lorawan.EUI64
	copy(devEUI[:], req.Item.DevEui)

	d, err := storage.GetDevice(storage.DB(), devEUI)
	if err != nil {
		return nil, errToRPCError(err)
	}

	dp, err := storage.GetAndCacheDeviceProfile(storage.DB(), storage.RedisPool(), d.DeviceProfileID)
	if err != nil {
		return nil, errToRPCError(err)
	}

	ds, err := storage.GetDeviceSession(storage.RedisPool(), d.DevEUI)
	if err != nil {
		return nil, errToRPCError(err)
	}

	var devAddr lorawan.DevAddr
	copy(devAddr[:], req.Item.DevAddr)

	if (devAddr != lorawan.DevAddr{0, 0, 0, 0} && ds.DevAddr != devAddr) {
		return nil, grpc.Errorf(codes.InvalidArgument, "device security-context out of sync")
	}

	qi := storage.DeviceQueueItem{
		DevAddr:    devAddr,
		DevEUI:     d.DevEUI,
		FRMPayload: req.Item.FrmPayload,
		FCnt:       req.Item.FCnt,
		FPort:      uint8(req.Item.FPort),
		Confirmed:  req.Item.Confirmed,
	}

	// When the device is operating in Class-B and has a beacon lock, calculate
	// the next ping-slot.
	if dp.SupportsClassB {
		// check if device is currently active and is operating in Class-B mode
		ds, err := storage.GetDeviceSession(storage.RedisPool(), d.DevEUI)
		if err != nil && err != storage.ErrDoesNotExist {
			return nil, errToRPCError(err)
		}

		if err == nil && ds.BeaconLocked {
			scheduleAfterGPSEpochTS, err := storage.GetMaxEmitAtTimeSinceGPSEpochForDevEUI(storage.DB(), d.DevEUI)
			if err != nil {
				return nil, errToRPCError(err)
			}

			if scheduleAfterGPSEpochTS == 0 {
				scheduleAfterGPSEpochTS = gps.Time(time.Now()).TimeSinceGPSEpoch()
			}

			// take some margin into account
			scheduleAfterGPSEpochTS += classBScheduleMargin

			gpsEpochTS, err := classb.GetNextPingSlotAfter(scheduleAfterGPSEpochTS, ds.DevAddr, ds.PingSlotNb)
			if err != nil {
				return nil, errToRPCError(err)
			}

			timeoutTime := time.Time(gps.NewFromTimeSinceGPSEpoch(gpsEpochTS)).Add(time.Second * time.Duration(dp.ClassBTimeout))
			qi.EmitAtTimeSinceGPSEpoch = &gpsEpochTS
			qi.TimeoutAfter = &timeoutTime
		}
	}

	err = storage.CreateDeviceQueueItem(storage.DB(), &qi)
	if err != nil {
		return nil, errToRPCError(err)
	}

	return &empty.Empty{}, nil
}
469737
func (d *DataBagService) CreateItem(databagName string, databagItem DataBagItem) (err error) {
	body, err := JSONReader(databagItem)
	if err != nil {
		return
	}
	path := fmt.Sprintf("data/%s", databagName)
	return d.client.magicRequestDecoder("POST", path, body, nil)
}
759137
func (c *Manager) CreateLibraryItem(ctx context.Context, item Item) (string, error) {
	type createItemSpec struct {
		Name        string `json:"name"`
		Description string `json:"description"`
		LibraryID   string `json:"library_id,omitempty"`
		Type        string `json:"type"`
	}
	spec := struct {
		Item createItemSpec `json:"create_spec"`
	}{
		Item: createItemSpec{
			Name:        item.Name,
			Description: item.Description,
			LibraryID:   item.LibraryID,
			Type:        item.Type,
		},
	}
	url := internal.URL(c, internal.LibraryItemPath)
	var res string
	return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
}
144785
func (f *Flex) RemoveItem(p Primitive) *Flex {
	for index := len(f.items) - 1; index >= 0; index-- {
		if f.items[index].Item == p {
			f.items = append(f.items[:index], f.items[index+1:]...)
		}
	}
	return f
}