durable-cf-streams 0.1.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.
- package/README.md +134 -0
- package/dist/chunk-5N2UNHIW.js +306 -0
- package/dist/chunk-AU5YTPHF.js +239 -0
- package/dist/chunk-E7XMLPFW.js +275 -0
- package/dist/chunk-KHGAPSJ7.js +271 -0
- package/dist/chunk-LK4KY5UI.js +285 -0
- package/dist/chunk-VLDLQ6TP.js +15096 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +66 -0
- package/dist/interface-DFfkkkVM.d.ts +63 -0
- package/dist/storage/d1.d.ts +21 -0
- package/dist/storage/d1.js +8 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/index.js +20 -0
- package/dist/storage/kv.d.ts +21 -0
- package/dist/storage/kv.js +8 -0
- package/dist/storage/memory.d.ts +16 -0
- package/dist/storage/memory.js +8 -0
- package/dist/storage/r2.d.ts +23 -0
- package/dist/storage/r2.js +8 -0
- package/package.json +74 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { O as Offset } from './interface-DFfkkkVM.js';
|
|
2
|
+
export { A as AppendOptions, b as AppendResult, G as GetOptions, c as GetResult, H as HeadResult, P as PutOptions, a as PutResult, d as StreamMessage, e as StreamMetadata, S as StreamStore, W as WaitResult } from './interface-DFfkkkVM.js';
|
|
3
|
+
|
|
4
|
+
declare const generateCursor: () => string;
|
|
5
|
+
declare const parseCursor: (cursor: string) => number | null;
|
|
6
|
+
declare const isValidCursor: (cursor: string) => boolean;
|
|
7
|
+
declare const compareCursors: (a: string, b: string) => number;
|
|
8
|
+
declare const isNewerCursor: (cursor: string, clientCursor: string | undefined) => boolean;
|
|
9
|
+
declare const getNextCursor: (clientCursor: string | undefined) => string;
|
|
10
|
+
|
|
11
|
+
declare class StreamNotFoundError extends Error {
|
|
12
|
+
readonly _tag: "StreamNotFoundError";
|
|
13
|
+
readonly path: string;
|
|
14
|
+
constructor(path: string);
|
|
15
|
+
}
|
|
16
|
+
declare class StreamConflictError extends Error {
|
|
17
|
+
readonly _tag: "StreamConflictError";
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
declare class SequenceConflictError extends Error {
|
|
21
|
+
readonly _tag: "SequenceConflictError";
|
|
22
|
+
readonly expected: string;
|
|
23
|
+
readonly received: string;
|
|
24
|
+
constructor(expected: string, received: string);
|
|
25
|
+
}
|
|
26
|
+
declare class ContentTypeMismatchError extends Error {
|
|
27
|
+
readonly _tag: "ContentTypeMismatchError";
|
|
28
|
+
readonly expected: string;
|
|
29
|
+
readonly received: string;
|
|
30
|
+
constructor(expected: string, received: string);
|
|
31
|
+
}
|
|
32
|
+
declare class InvalidJsonError extends Error {
|
|
33
|
+
readonly _tag: "InvalidJsonError";
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
}
|
|
36
|
+
declare class InvalidOffsetError extends Error {
|
|
37
|
+
readonly _tag: "InvalidOffsetError";
|
|
38
|
+
constructor(offset: string);
|
|
39
|
+
}
|
|
40
|
+
declare class PayloadTooLargeError extends Error {
|
|
41
|
+
readonly _tag: "PayloadTooLargeError";
|
|
42
|
+
readonly maxBytes: number;
|
|
43
|
+
readonly receivedBytes: number;
|
|
44
|
+
constructor(maxBytes: number, receivedBytes: number);
|
|
45
|
+
}
|
|
46
|
+
type StreamError = StreamNotFoundError | StreamConflictError | SequenceConflictError | ContentTypeMismatchError | InvalidJsonError | InvalidOffsetError | PayloadTooLargeError;
|
|
47
|
+
|
|
48
|
+
type ParsedOffset = {
|
|
49
|
+
readonly seq: number;
|
|
50
|
+
readonly pos: number;
|
|
51
|
+
};
|
|
52
|
+
declare const initialOffset: () => Offset;
|
|
53
|
+
declare const isSentinelOffset: (offset: string) => boolean;
|
|
54
|
+
declare const isValidOffset: (offset: string) => boolean;
|
|
55
|
+
declare const normalizeOffset: (offset: string) => Offset;
|
|
56
|
+
declare const parseOffset: (offset: string) => ParsedOffset | null;
|
|
57
|
+
declare const formatOffset: (seq: number, pos: number) => Offset;
|
|
58
|
+
declare const compareOffsets: (a: Offset, b: Offset) => -1 | 0 | 1;
|
|
59
|
+
declare const advanceOffset: (offset: Offset, byteCount: number) => Offset;
|
|
60
|
+
declare const incrementSeq: (offset: Offset) => Offset;
|
|
61
|
+
|
|
62
|
+
declare const normalizeContentType: (contentType: string) => string;
|
|
63
|
+
declare const isJsonContentType: (contentType: string) => boolean;
|
|
64
|
+
declare const validateTTL: (ttl: string) => number | null;
|
|
65
|
+
declare const validateExpiresAt: (value: string) => Date | null;
|
|
66
|
+
declare const generateETag: (path: string, startOffset: Offset, endOffset: Offset) => string;
|
|
67
|
+
declare const parseETag: (etag: string) => {
|
|
68
|
+
path: string;
|
|
69
|
+
startOffset: Offset;
|
|
70
|
+
endOffset: Offset;
|
|
71
|
+
} | null;
|
|
72
|
+
declare const processJsonAppend: (existing: Uint8Array, newData: Uint8Array) => Uint8Array;
|
|
73
|
+
declare const formatJsonResponse: (data: Uint8Array) => Uint8Array;
|
|
74
|
+
declare const validateJsonCreate: (data: Uint8Array, isPut: boolean) => Uint8Array;
|
|
75
|
+
|
|
76
|
+
export { ContentTypeMismatchError, InvalidJsonError, InvalidOffsetError, Offset, type ParsedOffset, PayloadTooLargeError, SequenceConflictError, StreamConflictError, type StreamError, StreamNotFoundError, advanceOffset, compareCursors, compareOffsets, formatJsonResponse, formatOffset, generateCursor, generateETag, getNextCursor, incrementSeq, initialOffset, isJsonContentType, isNewerCursor, isSentinelOffset, isValidCursor, isValidOffset, normalizeContentType, normalizeOffset, parseCursor, parseETag, parseOffset, processJsonAppend, validateExpiresAt, validateJsonCreate, validateTTL };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContentTypeMismatchError,
|
|
3
|
+
InvalidJsonError,
|
|
4
|
+
InvalidOffsetError,
|
|
5
|
+
PayloadTooLargeError,
|
|
6
|
+
SequenceConflictError,
|
|
7
|
+
StreamConflictError,
|
|
8
|
+
StreamNotFoundError,
|
|
9
|
+
advanceOffset,
|
|
10
|
+
compareCursors,
|
|
11
|
+
compareOffsets,
|
|
12
|
+
formatJsonResponse,
|
|
13
|
+
formatOffset,
|
|
14
|
+
generateCursor,
|
|
15
|
+
generateETag,
|
|
16
|
+
getNextCursor,
|
|
17
|
+
incrementSeq,
|
|
18
|
+
initialOffset,
|
|
19
|
+
isJsonContentType,
|
|
20
|
+
isNewerCursor,
|
|
21
|
+
isSentinelOffset,
|
|
22
|
+
isValidCursor,
|
|
23
|
+
isValidOffset,
|
|
24
|
+
normalizeContentType,
|
|
25
|
+
normalizeOffset,
|
|
26
|
+
parseCursor,
|
|
27
|
+
parseETag,
|
|
28
|
+
parseOffset,
|
|
29
|
+
processJsonAppend,
|
|
30
|
+
validateExpiresAt,
|
|
31
|
+
validateJsonCreate,
|
|
32
|
+
validateTTL
|
|
33
|
+
} from "./chunk-5N2UNHIW.js";
|
|
34
|
+
export {
|
|
35
|
+
ContentTypeMismatchError,
|
|
36
|
+
InvalidJsonError,
|
|
37
|
+
InvalidOffsetError,
|
|
38
|
+
PayloadTooLargeError,
|
|
39
|
+
SequenceConflictError,
|
|
40
|
+
StreamConflictError,
|
|
41
|
+
StreamNotFoundError,
|
|
42
|
+
advanceOffset,
|
|
43
|
+
compareCursors,
|
|
44
|
+
compareOffsets,
|
|
45
|
+
formatJsonResponse,
|
|
46
|
+
formatOffset,
|
|
47
|
+
generateCursor,
|
|
48
|
+
generateETag,
|
|
49
|
+
getNextCursor,
|
|
50
|
+
incrementSeq,
|
|
51
|
+
initialOffset,
|
|
52
|
+
isJsonContentType,
|
|
53
|
+
isNewerCursor,
|
|
54
|
+
isSentinelOffset,
|
|
55
|
+
isValidCursor,
|
|
56
|
+
isValidOffset,
|
|
57
|
+
normalizeContentType,
|
|
58
|
+
normalizeOffset,
|
|
59
|
+
parseCursor,
|
|
60
|
+
parseETag,
|
|
61
|
+
parseOffset,
|
|
62
|
+
processJsonAppend,
|
|
63
|
+
validateExpiresAt,
|
|
64
|
+
validateJsonCreate,
|
|
65
|
+
validateTTL
|
|
66
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
type Offset = string;
|
|
2
|
+
type StreamMessage = {
|
|
3
|
+
readonly offset: Offset;
|
|
4
|
+
readonly timestamp: number;
|
|
5
|
+
readonly data: Uint8Array;
|
|
6
|
+
};
|
|
7
|
+
type StreamMetadata = {
|
|
8
|
+
readonly path: string;
|
|
9
|
+
readonly contentType: string;
|
|
10
|
+
readonly ttlSeconds?: number;
|
|
11
|
+
readonly expiresAt?: string;
|
|
12
|
+
readonly createdAt: number;
|
|
13
|
+
};
|
|
14
|
+
type PutOptions = {
|
|
15
|
+
readonly contentType: string;
|
|
16
|
+
readonly ttlSeconds?: number;
|
|
17
|
+
readonly expiresAt?: string;
|
|
18
|
+
readonly data?: Uint8Array;
|
|
19
|
+
};
|
|
20
|
+
type PutResult = {
|
|
21
|
+
readonly created: boolean;
|
|
22
|
+
readonly nextOffset: Offset;
|
|
23
|
+
};
|
|
24
|
+
type AppendOptions = {
|
|
25
|
+
readonly contentType?: string;
|
|
26
|
+
readonly seq?: string;
|
|
27
|
+
};
|
|
28
|
+
type AppendResult = {
|
|
29
|
+
readonly nextOffset: Offset;
|
|
30
|
+
};
|
|
31
|
+
type GetOptions = {
|
|
32
|
+
readonly offset?: Offset;
|
|
33
|
+
};
|
|
34
|
+
type GetResult = {
|
|
35
|
+
readonly messages: StreamMessage[];
|
|
36
|
+
readonly nextOffset: Offset;
|
|
37
|
+
readonly upToDate: boolean;
|
|
38
|
+
readonly cursor: string;
|
|
39
|
+
readonly etag: string;
|
|
40
|
+
readonly contentType: string;
|
|
41
|
+
};
|
|
42
|
+
type HeadResult = {
|
|
43
|
+
readonly contentType: string;
|
|
44
|
+
readonly nextOffset: Offset;
|
|
45
|
+
readonly etag: string;
|
|
46
|
+
};
|
|
47
|
+
type WaitResult = {
|
|
48
|
+
readonly messages: StreamMessage[];
|
|
49
|
+
readonly timedOut: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type StreamStore = {
|
|
53
|
+
put(path: string, options: PutOptions): Promise<PutResult>;
|
|
54
|
+
append(path: string, data: Uint8Array, options?: AppendOptions): Promise<AppendResult>;
|
|
55
|
+
get(path: string, options?: GetOptions): Promise<GetResult>;
|
|
56
|
+
head(path: string): Promise<HeadResult | null>;
|
|
57
|
+
delete(path: string): Promise<void>;
|
|
58
|
+
has(path: string): boolean;
|
|
59
|
+
waitForData(path: string, offset: Offset, timeoutMs: number): Promise<WaitResult>;
|
|
60
|
+
formatResponse(path: string, messages: StreamMessage[]): Uint8Array;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type { AppendOptions as A, GetOptions as G, HeadResult as H, Offset as O, PutOptions as P, StreamStore as S, WaitResult as W, PutResult as a, AppendResult as b, GetResult as c, StreamMessage as d, StreamMetadata as e };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { S as StreamStore, P as PutOptions, a as PutResult, A as AppendOptions, b as AppendResult, G as GetOptions, c as GetResult, H as HeadResult, O as Offset, W as WaitResult, d as StreamMessage } from '../interface-DFfkkkVM.js';
|
|
2
|
+
|
|
3
|
+
declare class D1Store implements StreamStore {
|
|
4
|
+
private readonly db;
|
|
5
|
+
private readonly waiters;
|
|
6
|
+
private readonly streamCache;
|
|
7
|
+
constructor(db: D1Database);
|
|
8
|
+
static schema: string;
|
|
9
|
+
initialize(): Promise<void>;
|
|
10
|
+
put(path: string, options: PutOptions): Promise<PutResult>;
|
|
11
|
+
append(path: string, data: Uint8Array, options?: AppendOptions): Promise<AppendResult>;
|
|
12
|
+
get(path: string, options?: GetOptions): Promise<GetResult>;
|
|
13
|
+
head(path: string): Promise<HeadResult | null>;
|
|
14
|
+
delete(path: string): Promise<void>;
|
|
15
|
+
has(path: string): boolean;
|
|
16
|
+
waitForData(path: string, offset: Offset, timeoutMs: number): Promise<WaitResult>;
|
|
17
|
+
formatResponse(path: string, messages: StreamMessage[]): Uint8Array;
|
|
18
|
+
private notifyWaiters;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { D1Store };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
D1Store
|
|
3
|
+
} from "../chunk-E7XMLPFW.js";
|
|
4
|
+
import {
|
|
5
|
+
KVStore
|
|
6
|
+
} from "../chunk-KHGAPSJ7.js";
|
|
7
|
+
import {
|
|
8
|
+
MemoryStore
|
|
9
|
+
} from "../chunk-AU5YTPHF.js";
|
|
10
|
+
import {
|
|
11
|
+
R2Store
|
|
12
|
+
} from "../chunk-LK4KY5UI.js";
|
|
13
|
+
import "../chunk-VLDLQ6TP.js";
|
|
14
|
+
import "../chunk-5N2UNHIW.js";
|
|
15
|
+
export {
|
|
16
|
+
D1Store,
|
|
17
|
+
KVStore,
|
|
18
|
+
MemoryStore,
|
|
19
|
+
R2Store
|
|
20
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { S as StreamStore, P as PutOptions, a as PutResult, A as AppendOptions, b as AppendResult, G as GetOptions, c as GetResult, H as HeadResult, O as Offset, W as WaitResult, d as StreamMessage } from '../interface-DFfkkkVM.js';
|
|
2
|
+
|
|
3
|
+
declare class KVStore implements StreamStore {
|
|
4
|
+
private readonly kv;
|
|
5
|
+
private readonly waiters;
|
|
6
|
+
private readonly streamCache;
|
|
7
|
+
constructor(kv: KVNamespace);
|
|
8
|
+
private metaKey;
|
|
9
|
+
private dataKey;
|
|
10
|
+
put(path: string, options: PutOptions): Promise<PutResult>;
|
|
11
|
+
append(path: string, data: Uint8Array, options?: AppendOptions): Promise<AppendResult>;
|
|
12
|
+
get(path: string, options?: GetOptions): Promise<GetResult>;
|
|
13
|
+
head(path: string): Promise<HeadResult | null>;
|
|
14
|
+
delete(path: string): Promise<void>;
|
|
15
|
+
has(path: string): boolean;
|
|
16
|
+
waitForData(path: string, offset: Offset, timeoutMs: number): Promise<WaitResult>;
|
|
17
|
+
formatResponse(path: string, messages: StreamMessage[]): Uint8Array;
|
|
18
|
+
private notifyWaiters;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { KVStore };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { S as StreamStore, P as PutOptions, a as PutResult, A as AppendOptions, b as AppendResult, G as GetOptions, c as GetResult, H as HeadResult, O as Offset, W as WaitResult, d as StreamMessage } from '../interface-DFfkkkVM.js';
|
|
2
|
+
|
|
3
|
+
declare class MemoryStore implements StreamStore {
|
|
4
|
+
private readonly streams;
|
|
5
|
+
put(path: string, options: PutOptions): Promise<PutResult>;
|
|
6
|
+
append(path: string, data: Uint8Array, options?: AppendOptions): Promise<AppendResult>;
|
|
7
|
+
get(path: string, options?: GetOptions): Promise<GetResult>;
|
|
8
|
+
head(path: string): Promise<HeadResult | null>;
|
|
9
|
+
delete(path: string): Promise<void>;
|
|
10
|
+
has(path: string): boolean;
|
|
11
|
+
waitForData(path: string, offset: Offset, timeoutMs: number): Promise<WaitResult>;
|
|
12
|
+
formatResponse(path: string, messages: StreamMessage[]): Uint8Array;
|
|
13
|
+
private notifyWaiters;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { MemoryStore };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { S as StreamStore, P as PutOptions, a as PutResult, A as AppendOptions, b as AppendResult, G as GetOptions, c as GetResult, H as HeadResult, O as Offset, W as WaitResult, d as StreamMessage } from '../interface-DFfkkkVM.js';
|
|
2
|
+
|
|
3
|
+
declare class R2Store implements StreamStore {
|
|
4
|
+
private readonly bucket;
|
|
5
|
+
private readonly waiters;
|
|
6
|
+
private readonly streamCache;
|
|
7
|
+
constructor(bucket: R2Bucket);
|
|
8
|
+
private metaKey;
|
|
9
|
+
private dataKey;
|
|
10
|
+
private getMetadata;
|
|
11
|
+
private getData;
|
|
12
|
+
put(path: string, options: PutOptions): Promise<PutResult>;
|
|
13
|
+
append(path: string, data: Uint8Array, options?: AppendOptions): Promise<AppendResult>;
|
|
14
|
+
get(path: string, options?: GetOptions): Promise<GetResult>;
|
|
15
|
+
head(path: string): Promise<HeadResult | null>;
|
|
16
|
+
delete(path: string): Promise<void>;
|
|
17
|
+
has(path: string): boolean;
|
|
18
|
+
waitForData(path: string, offset: Offset, timeoutMs: number): Promise<WaitResult>;
|
|
19
|
+
formatResponse(path: string, messages: StreamMessage[]): Uint8Array;
|
|
20
|
+
private notifyWaiters;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { R2Store };
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "durable-cf-streams",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "pure building blocks for durable streams on cloudflare",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/flbn/durable-cf-streams.git",
|
|
9
|
+
"directory": "packages/durable-cf-streams"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"cloudflare",
|
|
13
|
+
"workers",
|
|
14
|
+
"durable-objects",
|
|
15
|
+
"streams",
|
|
16
|
+
"d1",
|
|
17
|
+
"kv",
|
|
18
|
+
"r2"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./storage": {
|
|
29
|
+
"types": "./dist/storage/index.d.ts",
|
|
30
|
+
"import": "./dist/storage/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./storage/memory": {
|
|
33
|
+
"types": "./dist/storage/memory.d.ts",
|
|
34
|
+
"import": "./dist/storage/memory.js"
|
|
35
|
+
},
|
|
36
|
+
"./storage/d1": {
|
|
37
|
+
"types": "./dist/storage/d1.d.ts",
|
|
38
|
+
"import": "./dist/storage/d1.js"
|
|
39
|
+
},
|
|
40
|
+
"./storage/kv": {
|
|
41
|
+
"types": "./dist/storage/kv.d.ts",
|
|
42
|
+
"import": "./dist/storage/kv.js"
|
|
43
|
+
},
|
|
44
|
+
"./storage/r2": {
|
|
45
|
+
"types": "./dist/storage/r2.d.ts",
|
|
46
|
+
"import": "./dist/storage/r2.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"sideEffects": false,
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=22"
|
|
55
|
+
},
|
|
56
|
+
"volta": {
|
|
57
|
+
"node": "22.16.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"check": "tsc --noEmit"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"effect": "^3.19.13"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@cloudflare/workers-types": "^4.20241218.0",
|
|
68
|
+
"tsup": "^8.0.0",
|
|
69
|
+
"typescript": "^5.9.3"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"@cloudflare/workers-types": "^4.0.0"
|
|
73
|
+
}
|
|
74
|
+
}
|