Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blocksuite/store

Package Overview
Dependencies
Maintainers
4
Versions
1277
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocksuite/store - npm Package Compare versions

Comparing version 0.3.0-alpha.7 to 0.3.0-alpha.8

2

dist/base.d.ts

@@ -21,3 +21,3 @@ import type { Page } from './workspace';

text?: TextType;
source?: string;
sourceId?: string;
constructor(page: Page, props: Partial<IBaseBlockProps>);

@@ -24,0 +24,0 @@ firstChild(): BaseBlockModel | null;

// Test page entry located in playground/examples/blob/index.html
import { BlobStorage, IndexedDBBlobProvider } from '..';
import { getBlobStorage } from '..';
import { testSerial, runOnce, loadTestImageBlob, loadImage, assertColor, assertExists, disableButtonsAfterClick, } from '../../__tests__/test-utils-dom';
async function testBasic() {
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init('test');
storage.addProvider(provider);
const storage = await getBlobStorage('test', '');
assertExists(storage);
const blob = await loadTestImageBlob('test-card-1');

@@ -59,5 +58,4 @@ let id = undefined;

clearIndexedDB();
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init('test');
storage.addProvider(provider);
const storage = await getBlobStorage('test', '');
assertExists(storage);
testSerial('can set blob', async () => {

@@ -71,5 +69,4 @@ const blob = await loadTestImageBlob('test-card-2');

async function testRefreshAfter() {
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init('test');
storage.addProvider(provider);
const storage = await getBlobStorage('test', '');
assertExists(storage);
testSerial('can get saved blob', async () => {

@@ -102,5 +99,4 @@ const id = storage.blobs.values().next().value;

clearIndexedDB();
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init('test', 'http://localhost:3000/api/blobs');
storage.addProvider(provider);
const storage = await getBlobStorage('test', 'http://localhost:3000/api/blobs');
assertExists(storage);
testSerial('can set blob', async () => {

@@ -116,5 +112,4 @@ const blob = await loadTestImageBlob('test-card-2');

clearIndexedDB();
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init('test', 'http://localhost:3000/api/blobs');
storage.addProvider(provider);
const storage = await getBlobStorage('test', 'http://localhost:3000/api/blobs');
assertExists(storage);
testSerial('can get saved blob', async () => {

@@ -121,0 +116,0 @@ // the test-card-2's hash

@@ -0,3 +1,4 @@

import { BlobStorage } from './storage';
export declare const getBlobStorage: (workspace?: string, cloudApi?: string) => Promise<BlobStorage | null>;
export { BlobStorage } from './storage';
export { IndexedDBBlobProvider } from './providers';
//# sourceMappingURL=index.d.ts.map

@@ -0,3 +1,14 @@

import { IndexedDBBlobProvider } from './providers';
import { BlobStorage } from './storage';
const CLOUD_API = '/api/blobs';
export const getBlobStorage = async (workspace, cloudApi = CLOUD_API) => {
if (workspace) {
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init(workspace, cloudApi);
storage.addProvider(provider);
return storage;
}
return null;
};
export { BlobStorage } from './storage';
export { IndexedDBBlobProvider } from './providers';
//# sourceMappingURL=index.js.map

@@ -72,4 +72,4 @@ import * as Y from 'yjs';

}
if (props.flavour === 'affine:embed' && !yBlock.has('prop:source')) {
yBlock.set('prop:source', props.source ?? '');
if (props.flavour === 'affine:embed' && !yBlock.has('prop:sourceId')) {
yBlock.set('prop:sourceId', props.sourceId ?? '');
}

@@ -79,2 +79,13 @@ if (props.flavour === 'affine:embed' && !yBlock.has('prop:caption')) {

}
if (props.flavour === 'affine:shape') {
if (!yBlock.has('prop:xywh')) {
yBlock.set('prop:xywh', props.xywh ?? '[0,0,50,50]');
}
if (!yBlock.has('prop:type')) {
yBlock.set('prop:type', props.type ?? 'rectangle');
}
if (!yBlock.has('prop:color')) {
yBlock.set('prop:color', props.color ?? 'black');
}
}
}

@@ -81,0 +92,0 @@ export function trySyncTextProp(splitSet, yBlock, text) {

export { Workspace } from './workspace';
export type { PageMeta } from './workspace';
export { Page } from './page';
//# sourceMappingURL=index.d.ts.map

@@ -39,2 +39,3 @@ import * as Y from 'yjs';

constructor(workspace: Workspace, id: string, doc: Y.Doc, awareness: Awareness, idGenerator?: IdGenerator);
get blobs(): Promise<import("..").BlobStorage | null>;
get pageId(): string;

@@ -41,0 +42,0 @@ /** key-value store of blocks */

@@ -73,2 +73,5 @@ import * as Y from 'yjs';

}
get blobs() {
return this.workspace.blobs;
}
get pageId() {

@@ -75,0 +78,0 @@ return this.id.replace('space:', '');

@@ -9,9 +9,8 @@ import * as Y from 'yjs';

import type { BaseBlockModel } from '../base';
import { BlobStorage } from '../blob';
export interface PageMeta {
id: string;
title: string;
favorite: boolean;
trash: boolean;
createDate: number;
trashDate: number | null;
[key: string]: string | number | boolean;
}

@@ -35,2 +34,3 @@ declare class WorkspaceMeta extends Space {

private _indexer;
private _blobStorage;
meta: WorkspaceMeta;

@@ -45,2 +45,3 @@ signals: {

get providers(): import("..").DocProvider[];
get blobs(): Promise<BlobStorage | null>;
private get _pages();

@@ -50,3 +51,3 @@ get doc(): Y.Doc;

private _hasPage;
getPage(pageId: string): Page;
getPage(pageId: string): Page | null;
private _handlePageEvent;

@@ -53,0 +54,0 @@ createPage(pageId: string): void;

@@ -7,3 +7,3 @@ import * as Y from 'yjs';

import { Indexer } from './search';
import { assertExists } from '../utils/utils';
import { getBlobStorage } from '../blob';
class WorkspaceMeta extends Space {

@@ -56,8 +56,5 @@ constructor(id, doc, awareness) {

this._yPages.push([yPage]);
yPage.set('id', page.id);
yPage.set('title', page.title);
yPage.set('favorite', page.favorite);
yPage.set('trash', page.trash);
yPage.set('createDate', page.createDate);
yPage.set('trashDate', page.trashDate);
Object.entries(page).forEach(([key, value]) => {
yPage.set(key, value);
});
}

@@ -76,20 +73,5 @@ else {

const yPage = this._yPages.get(index);
if ('id' in props) {
yPage.set('id', props.id ?? pages[index]['id']);
}
if ('title' in props) {
yPage.set('title', props.title ?? pages[index]['title']);
}
if ('favorite' in props) {
yPage.set('favorite', props.favorite ?? pages[index]['favorite']);
}
if ('trash' in props) {
yPage.set('trash', props.trash ?? pages[index]['trash']);
}
if ('createDate' in props) {
yPage.set('createDate', props.createDate ?? pages[index]['createDate']);
}
if ('trashDate' in props) {
yPage.set('trashDate', props.trashDate ?? pages[index]['trashDate']);
}
Object.entries(props).forEach(([key, value]) => {
yPage.set(key, value);
});
});

@@ -112,2 +94,3 @@ }

this._indexer = new Indexer(this.doc);
this._blobStorage = getBlobStorage(options.room);
this.meta = new WorkspaceMeta('space:meta', this.doc, this._store.awareness);

@@ -124,2 +107,5 @@ this.signals = {

}
get blobs() {
return this._blobStorage;
}
get _pages() {

@@ -145,4 +131,3 @@ // the meta space is not included

}
const page = this._pages.get(pageId);
assertExists(page);
const page = this._pages.get(pageId) ?? null;
return page;

@@ -170,6 +155,3 @@ }

title: '',
favorite: false,
trash: false,
createDate: +new Date(),
trashDate: null,
});

@@ -176,0 +158,0 @@ }

{
"name": "@blocksuite/store",
"version": "0.3.0-alpha.7",
"version": "0.3.0-alpha.8",
"description": "BlockSuite data store built for general purpose state management.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -18,3 +18,4 @@ // checkout https://vitest.dev/guide/debugging.html for debugging tests

import { DividerBlockModel } from '../../../blocks/src/divider-block/divider-model';
import { PageMeta } from '../workspace/workspace';
import type { PageMeta } from '../workspace';
import { assertExists } from '../utils/utils';

@@ -52,3 +53,5 @@ function createTestOptions() {

await waitOnce(workspace.signals.pageAdded);
return workspace.getPage(pageId);
const page = workspace.getPage(pageId);
assertExists(page);
return page;
}

@@ -84,5 +87,2 @@

title: '',
favorite: false,
trash: false,
trashDate: null,
},

@@ -234,11 +234,6 @@ ],

assert.deepEqual(
workspace.meta.pageMetas.map(
({ id, title, favorite, trash, trashDate }) => ({
id,
title,
favorite,
trash,
trashDate,
})
),
workspace.meta.pageMetas.map(({ id, title }) => ({
id,
title,
})),
[

@@ -248,5 +243,2 @@ {

title: '',
favorite: false,
trash: false,
trashDate: null,
},

@@ -258,11 +250,7 @@ ]

assert.deepEqual(
workspace.meta.pageMetas.map(
({ id, title, favorite, trash, trashDate }) => ({
id,
title,
favorite,
trash,
trashDate,
})
),
workspace.meta.pageMetas.map(({ id, title, favorite }) => ({
id,
title,
favorite,
})),
[

@@ -273,4 +261,2 @@ {

favorite: true,
trash: false,
trashDate: null,
},

@@ -277,0 +263,0 @@ ]

@@ -27,3 +27,3 @@ import type { Page } from './workspace';

text?: TextType;
source?: string;
sourceId?: string;

@@ -30,0 +30,0 @@ constructor(page: Page, props: Partial<IBaseBlockProps>) {

// Test page entry located in playground/examples/blob/index.html
import { BlobStorage, IndexedDBBlobProvider } from '..';
import { getBlobStorage } from '..';
import {

@@ -14,5 +14,4 @@ testSerial,

async function testBasic() {
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init('test');
storage.addProvider(provider);
const storage = await getBlobStorage('test', '');
assertExists(storage);

@@ -88,6 +87,6 @@ const blob = await loadTestImageBlob('test-card-1');

clearIndexedDB();
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init('test');
storage.addProvider(provider);
const storage = await getBlobStorage('test', '');
assertExists(storage);
testSerial('can set blob', async () => {

@@ -103,5 +102,4 @@ const blob = await loadTestImageBlob('test-card-2');

async function testRefreshAfter() {
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init('test');
storage.addProvider(provider);
const storage = await getBlobStorage('test', '');
assertExists(storage);

@@ -142,8 +140,7 @@ testSerial('can get saved blob', async () => {

clearIndexedDB();
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init(
const storage = await getBlobStorage(
'test',
'http://localhost:3000/api/blobs'
);
storage.addProvider(provider);
assertExists(storage);

@@ -162,8 +159,7 @@ testSerial('can set blob', async () => {

clearIndexedDB();
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init(
const storage = await getBlobStorage(
'test',
'http://localhost:3000/api/blobs'
);
storage.addProvider(provider);
assertExists(storage);

@@ -170,0 +166,0 @@ testSerial('can get saved blob', async () => {

@@ -0,2 +1,20 @@

import { IndexedDBBlobProvider } from './providers';
import { BlobStorage } from './storage';
const CLOUD_API = '/api/blobs';
export const getBlobStorage = async (
workspace?: string,
cloudApi: string = CLOUD_API
) => {
if (workspace) {
const storage = new BlobStorage();
const provider = await IndexedDBBlobProvider.init(workspace, cloudApi);
storage.addProvider(provider);
return storage;
}
return null;
};
export { BlobStorage } from './storage';
export { IndexedDBBlobProvider } from './providers';

@@ -102,4 +102,4 @@ import * as Y from 'yjs';

}
if (props.flavour === 'affine:embed' && !yBlock.has('prop:source')) {
yBlock.set('prop:source', props.source ?? '');
if (props.flavour === 'affine:embed' && !yBlock.has('prop:sourceId')) {
yBlock.set('prop:sourceId', props.sourceId ?? '');
}

@@ -109,2 +109,13 @@ if (props.flavour === 'affine:embed' && !yBlock.has('prop:caption')) {

}
if (props.flavour === 'affine:shape') {
if (!yBlock.has('prop:xywh')) {
yBlock.set('prop:xywh', props.xywh ?? '[0,0,50,50]');
}
if (!yBlock.has('prop:type')) {
yBlock.set('prop:type', props.type ?? 'rectangle');
}
if (!yBlock.has('prop:color')) {
yBlock.set('prop:color', props.color ?? 'black');
}
}
}

@@ -111,0 +122,0 @@

export { Workspace } from './workspace';
export type { PageMeta } from './workspace';
export { Page } from './page';

@@ -96,2 +96,6 @@ import * as Y from 'yjs';

get blobs() {
return this.workspace.blobs;
}
get pageId() {

@@ -98,0 +102,0 @@ return this.id.replace('space:', '');

@@ -8,4 +8,4 @@ import * as Y from 'yjs';

import type { Awareness } from 'y-protocols/awareness';
import { assertExists } from '../utils/utils';
import type { BaseBlockModel } from '../base';
import { BlobStorage, getBlobStorage } from '../blob';

@@ -15,6 +15,4 @@ export interface PageMeta {

title: string;
favorite: boolean;
trash: boolean;
createDate: number;
trashDate: number | null;
[key: string]: string | number | boolean;
}

@@ -54,8 +52,5 @@

this._yPages.push([yPage]);
yPage.set('id', page.id);
yPage.set('title', page.title);
yPage.set('favorite', page.favorite);
yPage.set('trash', page.trash);
yPage.set('createDate', page.createDate);
yPage.set('trashDate', page.trashDate);
Object.entries(page).forEach(([key, value]) => {
yPage.set(key, value);
});
} else {

@@ -75,20 +70,5 @@ this._yPages.insert(index, [yPage]);

const yPage = this._yPages.get(index) as Y.Map<unknown>;
if ('id' in props) {
yPage.set('id', props.id ?? pages[index]['id']);
}
if ('title' in props) {
yPage.set('title', props.title ?? pages[index]['title']);
}
if ('favorite' in props) {
yPage.set('favorite', props.favorite ?? pages[index]['favorite']);
}
if ('trash' in props) {
yPage.set('trash', props.trash ?? pages[index]['trash']);
}
if ('createDate' in props) {
yPage.set('createDate', props.createDate ?? pages[index]['createDate']);
}
if ('trashDate' in props) {
yPage.set('trashDate', props.trashDate ?? pages[index]['trashDate']);
}
Object.entries(props).forEach(([key, value]) => {
yPage.set(key, value);
});
});

@@ -139,2 +119,3 @@ }

private _indexer: Indexer;
private _blobStorage: Promise<BlobStorage | null>;

@@ -154,2 +135,4 @@ meta: WorkspaceMeta;

this._indexer = new Indexer(this.doc);
this._blobStorage = getBlobStorage(options.room);
this.meta = new WorkspaceMeta(

@@ -174,2 +157,6 @@ 'space:meta',

get blobs() {
return this._blobStorage;
}
private get _pages() {

@@ -195,3 +182,3 @@ // the meta space is not included

getPage(pageId: string) {
getPage(pageId: string): Page | null {
if (!pageId.startsWith('space:')) {

@@ -201,4 +188,3 @@ pageId = 'space:' + pageId;

const page = this._pages.get(pageId);
assertExists(page);
const page = this._pages.get(pageId) ?? null;
return page;

@@ -236,6 +222,3 @@ }

title: '',
favorite: false,
trash: false,
createDate: +new Date(),
trashDate: null,
});

@@ -242,0 +225,0 @@ }

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

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