New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tldraw/store

Package Overview
Dependencies
Maintainers
4
Versions
1860
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tldraw/store - npm Package Compare versions

Comparing version 2.0.0-canary.e8bc114bf3cc to 2.0.0-canary.ed8d4d9e05fd

34

dist-cjs/index.d.ts

@@ -395,2 +395,9 @@ import { Atom } from '@tldraw/state';

/**
* A serialized snapshot of the record store's values.
*
* @public
*/
export declare type SerializedStore<R extends UnknownRecord> = Record<IdOf<R>, R>;
/**
* Squash a collection of diffs into a single diff.

@@ -439,3 +446,3 @@ *

/** The store's initial data. */
initialData?: StoreSnapshot<R>;
initialData?: SerializedStore<R>;
/**

@@ -527,3 +534,3 @@ * A map of validators for each record type. A record's validator will be called when the record

*/
serialize: (scope?: 'all' | RecordScope) => StoreSnapshot<R>;
serialize: (scope?: 'all' | RecordScope) => SerializedStore<R>;
/**

@@ -540,6 +547,3 @@ * Get a serialized snapshot of the store and its schema.

*/
getSnapshot(scope?: 'all' | RecordScope): {
store: StoreSnapshot<R>;
schema: SerializedSchema;
};
getSnapshot(scope?: 'all' | RecordScope): StoreSnapshot<R>;
/**

@@ -557,6 +561,3 @@ * Load a serialized snapshot.

*/
loadSnapshot(snapshot: {
store: StoreSnapshot<R>;
schema: SerializedSchema;
}): void;
loadSnapshot(snapshot: StoreSnapshot<R>): void;
/**

@@ -748,3 +749,3 @@ * Get an array of all values in the store.

migratePersistedRecord(record: R, persistedSchema: SerializedSchema, direction?: 'down' | 'up'): MigrationResult<R>;
migrateStoreSnapshot(storeSnapshot: StoreSnapshot<R>, persistedSchema: SerializedSchema): MigrationResult<StoreSnapshot<R>>;
migrateStoreSnapshot(storeSnapshot: SerializedStore<R>, persistedSchema: SerializedSchema): MigrationResult<SerializedStore<R>>;
/* Excluded from this release type: createIntegrityChecker */

@@ -770,8 +771,7 @@ serialize(): SerializedSchema;

/**
* A serialized snapshot of the record store's values.
*
* @public
*/
export declare type StoreSnapshot<R extends UnknownRecord> = Record<IdOf<R>, R>;
/** @public */
export declare type StoreSnapshot<R extends UnknownRecord> = {
store: SerializedStore<R>;
schema: SerializedSchema;
};

@@ -778,0 +778,0 @@ /** @public */

{
"name": "@tldraw/store",
"description": "A tiny little drawing app (store).",
"version": "2.0.0-canary.e8bc114bf3cc",
"version": "2.0.0-canary.ed8d4d9e05fd",
"packageManager": "yarn@3.5.0",

@@ -45,4 +45,4 @@ "author": {

"dependencies": {
"@tldraw/state": "2.0.0-canary.e8bc114bf3cc",
"@tldraw/utils": "2.0.0-canary.e8bc114bf3cc",
"@tldraw/state": "2.0.0-canary.ed8d4d9e05fd",
"@tldraw/utils": "2.0.0-canary.ed8d4d9e05fd",
"lodash.isequal": "^4.5.0",

@@ -49,0 +49,0 @@ "nanoid": "4.0.2"

@@ -10,2 +10,3 @@ export type { BaseRecord, IdOf, RecordId, UnknownRecord } from './lib/BaseRecord'

RecordsDiff,
SerializedStore,
StoreError,

@@ -12,0 +13,0 @@ StoreListener,

@@ -76,5 +76,11 @@ import { Atom, Computed, Reactor, atom, computed, reactor, transact } from '@tldraw/state'

*/
export type StoreSnapshot<R extends UnknownRecord> = Record<IdOf<R>, R>
export type SerializedStore<R extends UnknownRecord> = Record<IdOf<R>, R>
/** @public */
export type StoreSnapshot<R extends UnknownRecord> = {
store: SerializedStore<R>
schema: SerializedSchema
}
/** @public */
export type StoreValidator<R extends UnknownRecord> = {

@@ -167,3 +173,3 @@ validate: (record: unknown) => R

/** The store's initial data. */
initialData?: StoreSnapshot<R>
initialData?: SerializedStore<R>
/**

@@ -508,4 +514,4 @@ * A map of validators for each record type. A record's validator will be called when the record

*/
serialize = (scope: RecordScope | 'all' = 'document'): StoreSnapshot<R> => {
const result = {} as StoreSnapshot<R>
serialize = (scope: RecordScope | 'all' = 'document'): SerializedStore<R> => {
const result = {} as SerializedStore<R>
for (const [id, atom] of objectMapEntries(this.atoms.value)) {

@@ -531,3 +537,3 @@ const record = atom.value

*/
getSnapshot(scope: RecordScope | 'all' = 'document') {
getSnapshot(scope: RecordScope | 'all' = 'document'): StoreSnapshot<R> {
return {

@@ -551,3 +557,3 @@ store: this.serialize(scope),

*/
loadSnapshot(snapshot: { store: StoreSnapshot<R>; schema: SerializedSchema }): void {
loadSnapshot(snapshot: StoreSnapshot<R>): void {
const migrationResult = this.schema.migrateStoreSnapshot(snapshot.store, snapshot.schema)

@@ -554,0 +560,0 @@

import { getOwnProperty, objectMapValues } from '@tldraw/utils'
import { IdOf, UnknownRecord } from './BaseRecord'
import { RecordType } from './RecordType'
import { Store, StoreSnapshot } from './Store'
import { SerializedStore, Store } from './Store'
import {

@@ -192,5 +192,5 @@ MigrationFailureReason,

migrateStoreSnapshot(
storeSnapshot: StoreSnapshot<R>,
storeSnapshot: SerializedStore<R>,
persistedSchema: SerializedSchema
): MigrationResult<StoreSnapshot<R>> {
): MigrationResult<SerializedStore<R>> {
const migrations = this.options.snapshotMigrations

@@ -209,3 +209,3 @@ if (!migrations) {

if (ourStoreVersion > persistedStoreVersion) {
const result = migrate<StoreSnapshot<R>>({
const result = migrate<SerializedStore<R>>({
value: storeSnapshot,

@@ -212,0 +212,0 @@ migrations,

import { MigrationFailureReason } from '../migrate'
import { StoreSnapshot } from '../Store'
import { SerializedStore } from '../Store'
import { testSchemaV0 } from './testSchema.v0'

@@ -308,3 +308,3 @@ import { testSchemaV1 } from './testSchema.v1'

test('migrating a whole store snapshot works', () => {
const snapshot: StoreSnapshot<any> = {
const snapshot: SerializedStore<any> = {
'user-1': {

@@ -311,0 +311,0 @@ id: 'user-1',

import { assert } from '@tldraw/utils'
import { BaseRecord, RecordId } from '../BaseRecord'
import { createRecordType } from '../RecordType'
import { StoreSnapshot } from '../Store'
import { SerializedStore } from '../Store'
import { StoreSchema } from '../StoreSchema'

@@ -206,6 +206,6 @@ import { defineMigrations } from '../migrate'

[StoreVersions.RemoveOrg]: {
up: (store: StoreSnapshot<any>) => {
up: (store: SerializedStore<any>) => {
return Object.fromEntries(Object.entries(store).filter(([_, r]) => r.typeName !== 'org'))
},
down: (store: StoreSnapshot<any>) => {
down: (store: SerializedStore<any>) => {
// noop

@@ -212,0 +212,0 @@ return store

import { BaseRecord, IdOf, RecordId } from '../BaseRecord'
import { createRecordType } from '../RecordType'
import { Store, StoreSnapshot } from '../Store'
import { SerializedStore, Store } from '../Store'
import { StoreSchema } from '../StoreSchema'

@@ -93,3 +93,3 @@

describe('Validating initial data', () => {
let snapshot: StoreSnapshot<Book | Author>
let snapshot: SerializedStore<Book | Author>

@@ -96,0 +96,0 @@ beforeEach(() => {

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