Skip to content

Commit 5124339

Browse files
Copilothotlong
andcommitted
Fix browser compatibility issue by removing crypto dependency
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 926329a commit 5124339

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

packages/objectql/src/protocol.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,24 @@ import type {
1616
ListViewsResponse,
1717
SavedView
1818
} from '@objectstack/spec/api';
19-
import { createHash } from 'crypto';
2019

2120
// We import SchemaRegistry directly since this class lives in the same package
2221
import { SchemaRegistry } from './registry';
2322

23+
/**
24+
* Simple hash function for ETag generation (browser-compatible)
25+
* Uses a basic hash algorithm instead of crypto.createHash
26+
*/
27+
function simpleHash(str: string): string {
28+
let hash = 0;
29+
for (let i = 0; i < str.length; i++) {
30+
const char = str.charCodeAt(i);
31+
hash = ((hash << 5) - hash) + char;
32+
hash = hash & hash; // Convert to 32bit integer
33+
}
34+
return Math.abs(hash).toString(16);
35+
}
36+
2437
export class ObjectStackProtocolImplementation implements IObjectStackProtocol {
2538
private engine: IDataEngine;
2639
private viewStorage: Map<string, SavedView> = new Map();
@@ -131,9 +144,9 @@ export class ObjectStackProtocolImplementation implements IObjectStackProtocol {
131144
throw new Error(`Metadata item ${type}/${name} not found`);
132145
}
133146

134-
// Calculate ETag (MD5 hash of the stringified metadata)
147+
// Calculate ETag (simple hash of the stringified metadata)
135148
const content = JSON.stringify(item);
136-
const hash = createHash('md5').update(content).digest('hex');
149+
const hash = simpleHash(content);
137150
const etag = { value: hash, weak: false };
138151

139152
// Check If-None-Match header

0 commit comments

Comments
 (0)