Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/khaki-dots-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@podley/storage": patch
"@podley/test": patch
"@podley/web": patch
---

Update put and putBulk methods to return stored entities across all tabular repositories
update package dependencies
60 changes: 30 additions & 30 deletions bun.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
"tailwind-merge": "2.6.0"
},
"devDependencies": {
"@types/react": "^19.2.1",
"@types/react-dom": "^19.2.0",
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"@vitejs/plugin-react": "^5.0.4",
"autoprefixer": "10.4.21",
"postcss": "8.5.6",
"tailwindcss": "3.4.17",
"vite": "^7.1.9"
"vite": "^7.1.10"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"publish-manual": "bun ./scripts/publish-workspaces.ts"
},
"dependencies": {
"caniuse-lite": "^1.0.30001750"
"caniuse-lite": "^1.0.30001751"
},
"catalog": {
"@sinclair/typebox": "^0.34.41",
Expand All @@ -38,7 +38,7 @@
"@typescript-eslint/eslint-plugin": "^8.46.1",
"@typescript-eslint/parser": "^8.46.1",
"concurrently": "^9.2.1",
"eslint": "^9.37.0",
"eslint": "^9.38.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"@sinclair/typebox": "catalog:",
"pg": "^8.16.3",
"@types/pg": "^8.15.5",
"@supabase/supabase-js": "^2.74.0",
"fake-indexeddb": "^6.2.2"
"@supabase/supabase-js": "^2.75.1",
"fake-indexeddb": "=6.2.2"
},
"exports": {
".": {
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/src/kv/KvViaTabularRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export abstract class KvViaTabularRepository<
if (shouldStringify) {
value = JSON.stringify(value) as Value;
}
return await this.tabularRepository.put({ key, value });
await this.tabularRepository.put({ key, value });
}

/**
Expand All @@ -64,7 +64,7 @@ export abstract class KvViaTabularRepository<
return { key, value };
});

return await this.tabularRepository.putBulk(entities);
await this.tabularRepository.putBulk(entities);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions packages/storage/src/tabular/FsFolderTabularRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export class FsFolderTabularRepository<

/**
* Stores a row in the repository
* @param key - The primary key object
* @param value - The value object to store
* @param entity - The entity to store
* @returns The stored entity
* @emits 'put' event when successful
*/
async put(entity: Entity): Promise<void> {
async put(entity: Entity): Promise<Entity> {
await this.setupDirectory();
const filePath = await this.getFilePath(entity);
try {
Expand All @@ -89,16 +89,18 @@ export class FsFolderTabularRepository<
}
}
this.events.emit("put", entity);
return entity;
}

/**
* Stores multiple rows in the repository in a bulk operation
* @param entities - Array of entities to store
* @returns Array of stored entities
* @emits 'put' event for each entity stored
*/
async putBulk(entities: Entity[]): Promise<void> {
async putBulk(entities: Entity[]): Promise<Entity[]> {
await this.setupDirectory();
await Promise.all(entities.map(async (entity) => this.put(entity)));
return await Promise.all(entities.map(async (entity) => this.put(entity)));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/src/tabular/ITabularRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export interface ITabularRepository<
Entity = Static<Schema>,
> {
// Core methods
put(value: Entity): Promise<void>;
putBulk(values: Entity[]): Promise<void>;
put(value: Entity): Promise<Entity>;
putBulk(values: Entity[]): Promise<Entity[]>;
get(key: PrimaryKey): Promise<Entity | undefined>;
delete(key: PrimaryKey | Entity): Promise<void>;
getAll(): Promise<Entity[] | undefined>;
Expand Down
11 changes: 7 additions & 4 deletions packages/storage/src/tabular/InMemoryTabularRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,25 @@ export class InMemoryTabularRepository<
/**
* Stores a key-value pair in the repository
* @param value - The combined object to store
* @emits 'put' event with the fingerprint ID when successful
* @returns The stored entity
* @emits 'put' event with the stored entity when successful
*/
async put(value: Entity): Promise<void> {
async put(value: Entity): Promise<Entity> {
const { key } = this.separateKeyValueFromCombined(value);
const id = await makeFingerprint(key);
this.values.set(id, value);
this.events.emit("put", value);
return value;
}

/**
* Stores multiple key-value pairs in the repository in a bulk operation
* @param values - Array of combined objects to store
* @returns Array of stored entities
* @emits 'put' event for each value stored
*/
async putBulk(values: Entity[]): Promise<void> {
await Promise.all(values.map(async (value) => this.put(value)));
async putBulk(values: Entity[]): Promise<Entity[]> {
return await Promise.all(values.map(async (value) => this.put(value)));
}

/**
Expand Down
13 changes: 7 additions & 6 deletions packages/storage/src/tabular/IndexedDbTabularRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ export class IndexedDbTabularRepository<

/**
* Stores a row in the repository.
* @param key - The key object.
* @param value - The value object to store.
* @param record - The entity to store.
* @returns The stored entity
* @emits put - Emitted when the value is successfully stored
*/
async put(record: Entity): Promise<void> {
async put(record: Entity): Promise<Entity> {
const db = await this.setupDatabase();
const { key } = this.separateKeyValueFromCombined(record);
// Merge key and value, ensuring all fields are at the root level for indexing
Expand All @@ -105,17 +105,18 @@ export class IndexedDbTabularRepository<
};
request.onsuccess = () => {
this.events.emit("put", record);
resolve();
resolve(record);
};
});
}

/**
* Stores multiple rows in the repository in a bulk operation.
* @param records - Array of entities to store.
* @returns Array of stored entities
* @emits put - Emitted for each record successfully stored
*/
async putBulk(records: Entity[]): Promise<void> {
async putBulk(records: Entity[]): Promise<Entity[]> {
const db = await this.setupDatabase();
return new Promise((resolve, reject) => {
const transaction = db.transaction(this.table, "readwrite");
Expand All @@ -133,7 +134,7 @@ export class IndexedDbTabularRepository<

transaction.oncomplete = () => {
if (!hasError) {
resolve();
resolve(records);
}
};

Expand Down
Loading