🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@isoftdata/svelte-store-crud

Package Overview
Dependencies
Maintainers
11
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@isoftdata/svelte-store-crud

This is a Svelte store for tracking CRUD operations.

npmnpm
Version
2.1.0
Version published
Weekly downloads
127
62.82%
Maintainers
11
Weekly downloads
 
Created
Source

Svelte Store CRUD

This is a Svelte store for tracking CRUD operations.

For example, if you have a map of entities and want to track when they are created, updated, and deleted without having to add a bunch of boolean flags to each entity, this store can help.

This store's value is an object containing three maps of objects, created, updated, and deleted.

Install

	npm i @isoftdata/svelte-store-crud

Breaking Changes

2.0.0

  • Require Svelte 5
  • Deprecate the old makeCrudStore function. Use the CrudRuneStore class instead

API

CrudRuneStore<T, K>

const crudStore = new CrudRuneStore<Entity, 'id'>('id')

Creates a CRUD store for tracking changes to objects of type T, tracked by a key of type K.

This has the same API as the Svelte 4 version powered by Svelte stores, except for the subscribe function as it is not needed. Since it is written with runes, all fields and functions should be reactive if referenced in an effect.

Properties on the store are described below:

create(entity: T): void

Add an entity to the created map.

update(entity: T): void

Add an entity to the updated map.

If you call this function with an entity whose id is in the created map, it will update it in that map instead of adding it to the updated map.

delete(entity: T): void

Add an entity to the deleted map.

If you call this function with an entity whose id is in the created map, that entity will be removed from the created map, and will be put in the deleted map.

If you call this function with an entity whose id is in the updated map, it will be removed from the updated map and added to the deleted map.

unDelete(entity: T): void

Removes an entity from the deleted map.

This does not add it back to the created or updated map if it was in one before

get createdValues(): T[]

Get a list of all values in the created map

get updatedValues(): T[]

Get a list of all values in the updated map

get deletedValues(): T[]

Get a list of all values in the deleted map

hasChanges(): boolean

Returns true if there are any changes in the store

clear(type?: 'create' | 'update' | 'delete'): void

Clear the created, updated, and deleted maps. Or, if specified, clear just one.

import { CrudRuneStore } from '@isoftdata/svelte-store-crud'

type Entity = {
	id: string
	name: string
}

const crudStore = new CrudRuneStore<Entity, 'id'>('id')

// Create an entity with id = '1'
crudStore.create({
	id: '1',
	name: 'Entity 1'
})

// Update an entity with id = '1'
crudStore.update({
	id: '1',
	name: 'Entity 1 Updated'
})
// Delete an entity with id = '1'
crudStore.delete({
	id: '1',
	name: 'Entity 1 Updated'
})

// In a Svelte file, get the values reactively whenever the store is updated
$inspect(crudStore.createdValues)
$inspect(crudStore.updatedValues)
$inspect(crudStore.deletedValues)
$inspect(crudStore.hasChanges())

newCrudMap

Creates the map used internally in the CRUD store, but without all the store logic

doCrud

Does all the logic of adding, removing, and updating things in a "CRUD map" without all the store logic

Keywords

svelte

FAQs

Package last updated on 08 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts