@relayfile/core 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import { describe, expect, expectTypeOf, it } from "vitest";
2
+ import { computeDedupHash } from "./dedup.js";
3
+ describe("computeDedupHash coverage", () => {
4
+ it("is deterministic for the same inputs", () => {
5
+ const first = computeDedupHash("ws_acme", "push", "repo:abc:main");
6
+ const second = computeDedupHash("ws_acme", "push", "repo:abc:main");
7
+ expect(second).toBe(first);
8
+ });
9
+ it("differs when workspaceId differs", () => {
10
+ expect(computeDedupHash("ws_acme", "push", "repo:abc:main")).not.toBe(computeDedupHash("ws_other", "push", "repo:abc:main"));
11
+ });
12
+ });
13
+ describe("dedup type contracts", () => {
14
+ it("compile for ContentIdentity and DedupStore consumers", async () => {
15
+ const identity = {
16
+ kind: "push",
17
+ key: "repo:abc:main",
18
+ };
19
+ const store = {
20
+ async has(key) {
21
+ if (key !== "dedup-hash") {
22
+ return null;
23
+ }
24
+ return {
25
+ contentIdentity: identity,
26
+ opId: "op_123",
27
+ };
28
+ },
29
+ async put() {
30
+ return undefined;
31
+ },
32
+ };
33
+ expectTypeOf(identity).toMatchTypeOf();
34
+ expectTypeOf(store).toMatchTypeOf();
35
+ await expect(store.put("dedup-hash", {
36
+ contentIdentity: identity,
37
+ opId: "op_123",
38
+ }, 300)).resolves.toBeUndefined();
39
+ await expect(store.has("dedup-hash")).resolves.toEqual({
40
+ contentIdentity: identity,
41
+ opId: "op_123",
42
+ });
43
+ });
44
+ });
@@ -0,0 +1,18 @@
1
+ export interface ContentIdentity {
2
+ kind: string;
3
+ key: string;
4
+ }
5
+ export interface DedupEntry {
6
+ contentIdentity?: ContentIdentity;
7
+ opId?: string;
8
+ path?: string;
9
+ revision?: string;
10
+ correlationId?: string;
11
+ createdAt?: string;
12
+ metadata?: Record<string, string>;
13
+ }
14
+ export interface DedupStore {
15
+ has(key: string): Promise<DedupEntry | null>;
16
+ put(key: string, entry: DedupEntry, ttlSeconds: number): Promise<void>;
17
+ }
18
+ export declare function computeDedupHash(workspaceId: string, kind: string, key: string): string;
package/dist/dedup.js ADDED
@@ -0,0 +1,10 @@
1
+ import { createHash } from "node:crypto";
2
+ export function computeDedupHash(workspaceId, kind, key) {
3
+ return createHash("sha256")
4
+ .update(workspaceId)
5
+ .update("\0")
6
+ .update(kind)
7
+ .update("\0")
8
+ .update(key)
9
+ .digest("hex");
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { computeDedupHash } from "./dedup.js";
3
+ describe("computeDedupHash", () => {
4
+ it("returns a stable sha256 hex digest for the identity tuple", () => {
5
+ expect(computeDedupHash("ws_123", "blob", "abc")).toBe("6403ef0791ad402d60057410bad1327c1e960207979140e9eb76e783ab4563ca");
6
+ });
7
+ it("uses tuple boundaries so adjacent segments do not collide", () => {
8
+ expect(computeDedupHash("ab", "c", "d")).not.toBe(computeDedupHash("a", "bc", "d"));
9
+ });
10
+ });
package/dist/files.d.ts CHANGED
@@ -11,6 +11,7 @@
11
11
  * - provider inference from path
12
12
  */
13
13
  import type { StorageAdapter, FileRow, FileSemantics } from "./storage.js";
14
+ import type { ContentIdentity } from "./dedup.js";
14
15
  import { normalizePath } from "./utils.js";
15
16
  export interface WriteFileRequest {
16
17
  path: string;
@@ -20,6 +21,7 @@ export interface WriteFileRequest {
20
21
  encoding?: string;
21
22
  semantics?: FileSemantics;
22
23
  correlationId?: string;
24
+ contentIdentity?: ContentIdentity;
23
25
  }
24
26
  export interface WriteFileResult {
25
27
  opId: string;
@@ -40,6 +42,7 @@ export interface DeleteFileRequest {
40
42
  path: string;
41
43
  ifMatch: string;
42
44
  correlationId?: string;
45
+ contentIdentity?: ContentIdentity;
43
46
  }
44
47
  export type WriteResult = {
45
48
  ok: true;
package/dist/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export * from "./operations.js";
15
15
  export * from "./writeback.js";
16
16
  export * from "./webhooks.js";
17
17
  export * from "./export.js";
18
+ export * from "./dedup.js";
package/dist/index.js CHANGED
@@ -15,3 +15,4 @@ export * from "./operations.js";
15
15
  export * from "./writeback.js";
16
16
  export * from "./webhooks.js";
17
17
  export * from "./export.js";
18
+ export * from "./dedup.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relayfile/core",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Shared business logic for relayfile — file operations, ACL, queries, events, and writeback lifecycle",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",