@cxyhhhhh/qraft-pack-feed 0.0.0-stage → 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/dist/hub.d.ts +26 -0
- package/dist/hub.d.ts.map +1 -0
- package/dist/hub.js +44 -0
- package/dist/hub.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +22 -4
- package/README.md +0 -3
package/dist/hub.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StorageNamespace } from "@cxyhhhhh/qraft-core";
|
|
2
|
+
export interface FeedItem {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
url?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FeedSource {
|
|
8
|
+
id: string;
|
|
9
|
+
fetch(): Promise<FeedItem[]>;
|
|
10
|
+
}
|
|
11
|
+
export interface FeedSubscription {
|
|
12
|
+
sourceId: string;
|
|
13
|
+
scopeKey: string;
|
|
14
|
+
}
|
|
15
|
+
export interface FeedDelivery {
|
|
16
|
+
subscription: FeedSubscription;
|
|
17
|
+
item: FeedItem;
|
|
18
|
+
}
|
|
19
|
+
export interface FeedHub {
|
|
20
|
+
addSource(source: FeedSource): void;
|
|
21
|
+
subscribe(input: FeedSubscription): Promise<void>;
|
|
22
|
+
unsubscribe(input: FeedSubscription): Promise<void>;
|
|
23
|
+
poll(deliver: (delivery: FeedDelivery) => Promise<void> | void): Promise<number>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createFeedHub(storage: StorageNamespace): FeedHub;
|
|
26
|
+
//# sourceMappingURL=hub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../src/hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,gBAAgB,CAAC;IAC/B,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,OAAO;IACtB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,SAAS,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAClF;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAoChE"}
|
package/dist/hub.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function createFeedHub(storage) {
|
|
2
|
+
const sources = new Map();
|
|
3
|
+
return {
|
|
4
|
+
addSource(source) {
|
|
5
|
+
if (sources.has(source.id))
|
|
6
|
+
throw new Error(`Feed source "${source.id}" is already registered`);
|
|
7
|
+
sources.set(source.id, source);
|
|
8
|
+
},
|
|
9
|
+
async subscribe(input) {
|
|
10
|
+
const key = subscriptionKey(input);
|
|
11
|
+
const current = await storage.get(key) ?? [];
|
|
12
|
+
if (current.some((item) => item.scopeKey === input.scopeKey))
|
|
13
|
+
return;
|
|
14
|
+
await storage.set(key, [...current, input]);
|
|
15
|
+
},
|
|
16
|
+
async unsubscribe(input) {
|
|
17
|
+
const key = subscriptionKey(input);
|
|
18
|
+
const current = await storage.get(key) ?? [];
|
|
19
|
+
await storage.set(key, current.filter((item) => item.scopeKey !== input.scopeKey));
|
|
20
|
+
},
|
|
21
|
+
async poll(deliver) {
|
|
22
|
+
let delivered = 0;
|
|
23
|
+
for (const source of sources.values()) {
|
|
24
|
+
const items = await source.fetch();
|
|
25
|
+
const subscriptions = await storage.get(subscriptionKey({ sourceId: source.id })) ?? [];
|
|
26
|
+
for (const item of items) {
|
|
27
|
+
for (const subscription of subscriptions) {
|
|
28
|
+
const seenKey = `seen:${source.id}:${subscription.scopeKey}:${item.id}`;
|
|
29
|
+
if (await storage.get(seenKey))
|
|
30
|
+
continue;
|
|
31
|
+
await deliver({ subscription, item });
|
|
32
|
+
await storage.set(seenKey, true);
|
|
33
|
+
delivered += 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return delivered;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function subscriptionKey(input) {
|
|
42
|
+
return `subs:${input.sourceId}`;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=hub.js.map
|
package/dist/hub.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hub.js","sourceRoot":"","sources":["../src/hub.ts"],"names":[],"mappings":"AA8BA,MAAM,UAAU,aAAa,CAAC,OAAyB;IACrD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC9C,OAAO;QACL,SAAS,CAAC,MAAM;YACd,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,CAAC,EAAE,yBAAyB,CAAC,CAAC;YAChG,OAAO,CAAC,GAAG,CAAC,MAA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IAAI,aAAa,EAAE,CAAC;wBACzC,MAAM,OAAO,GAAG,QAAQ,MAAM,CAAC,EAAE,IAAI,YAAY,CAAC,QAAQ,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;wBACxE,IAAI,MAAM,OAAO,CAAC,GAAG,CAAU,OAAO,CAAC;4BAAE,SAAS;wBAClD,MAAM,OAAO,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;wBACtC,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;wBACjC,SAAS,IAAI,CAAC,CAAC;oBACjB,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAA2B;IAClD,OAAO,QAAQ,KAAK,CAAC,QAAQ,EAAE,CAAC;AAClC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type PackDefinition } from "@cxyhhhhh/qraft-core";
|
|
2
|
+
import { type FeedDelivery, type FeedHub } from "./hub.js";
|
|
3
|
+
export declare const PACK_ID: "@cxyhhhhh/qraft-pack-feed";
|
|
4
|
+
declare module "@cxyhhhhh/qraft-core" {
|
|
5
|
+
interface QraftServiceMap {
|
|
6
|
+
"feed.hub": FeedHub;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface FeedPackOptions {
|
|
10
|
+
intervalMs?: number;
|
|
11
|
+
deliver?: (delivery: FeedDelivery) => Promise<void> | void;
|
|
12
|
+
}
|
|
13
|
+
export declare function feedPack(options?: FeedPackOptions): PackDefinition;
|
|
14
|
+
export { createFeedHub } from "./hub.js";
|
|
15
|
+
export type { FeedDelivery, FeedHub, FeedItem, FeedSource, FeedSubscription } from "./hub.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAiB,KAAK,YAAY,EAAE,KAAK,OAAO,EAAyD,MAAM,UAAU,CAAC;AAEjI,eAAO,MAAM,OAAO,EAAG,kBAA2B,CAAC;AAEnD,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,eAAe;QACvB,UAAU,EAAE,OAAO,CAAC;KACrB;CACF;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,cAAc,CAmBtE;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { definePack } from "@cxyhhhhh/qraft-core";
|
|
2
|
+
import { createFeedHub } from "./hub.js";
|
|
3
|
+
export const PACK_ID = "@cxyhhhhh/qraft-pack-feed";
|
|
4
|
+
export function feedPack(options = {}) {
|
|
5
|
+
return definePack({
|
|
6
|
+
id: PACK_ID,
|
|
7
|
+
setup(ctx) {
|
|
8
|
+
const hub = createFeedHub(ctx.storage.namespace(PACK_ID));
|
|
9
|
+
const registration = ctx.services.provide("feed.hub", hub);
|
|
10
|
+
ctx.onDispose(() => registration.dispose());
|
|
11
|
+
const deliver = options.deliver;
|
|
12
|
+
if (options.intervalMs && deliver) {
|
|
13
|
+
const timer = ctx.scheduler.every(PACK_ID, options.intervalMs, async () => {
|
|
14
|
+
await hub.poll(deliver);
|
|
15
|
+
});
|
|
16
|
+
ctx.onDispose(() => {
|
|
17
|
+
timer.dispose();
|
|
18
|
+
ctx.scheduler.disposeOwner(PACK_ID);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export { createFeedHub } from "./hub.js";
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,aAAa,EAA0F,MAAM,UAAU,CAAC;AAEjI,MAAM,CAAC,MAAM,OAAO,GAAG,kBAA2B,CAAC;AAanD,MAAM,UAAU,QAAQ,CAAC,UAA2B,EAAE;IACpD,OAAO,UAAU,CAAC;QAChB,EAAE,EAAE,OAAO;QACX,KAAK,CAAC,GAAG;YACP,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YAC1D,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;YAC3D,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;YAChC,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,EAAE,CAAC;gBAClC,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE;oBACxE,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC1B,CAAC,CAAC,CAAC;gBACH,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;oBACjB,KAAK,CAAC,OAAO,EAAE,CAAC;oBAChB,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cxyhhhhh/qraft-pack-feed",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Feed polling, dedupe and subscription delivery.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": ["dist"],
|
|
7
|
+
"publishConfig": { "access": "public" },
|
|
8
|
+
"engines": { "node": ">=22.5" },
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@cxyhhhhh/qraft-core": "0.1.0"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/README.md
DELETED