@pagepocket/contracts 0.8.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,49 @@
1
+ export type MatchQuery = string | {
2
+ selector?: string;
3
+ tagName?: string;
4
+ id?: string;
5
+ attrs?: Record<string, string | RegExp | true>;
6
+ };
7
+ export type ReplaceAction = {
8
+ type: "replaceWithHtml";
9
+ html: string;
10
+ } | {
11
+ type: "replaceWithElement";
12
+ tagName: string;
13
+ textContent?: string;
14
+ html?: string;
15
+ attrs?: Record<string, string | null>;
16
+ } | {
17
+ type: "renameTag";
18
+ to: string;
19
+ keepAttributes?: boolean;
20
+ keepChildren?: boolean;
21
+ } | {
22
+ type: "remove";
23
+ };
24
+ export type ApplyOptions = {
25
+ scope?: "document" | "allFrames";
26
+ limit?: number | "all";
27
+ onReplaced?: "stop" | "continue";
28
+ };
29
+ export type ReplaceElementRule = {
30
+ name?: string;
31
+ match: MatchQuery;
32
+ replace: ReplaceAction;
33
+ apply?: ApplyOptions;
34
+ };
35
+ export type ReplaceElementContext = {
36
+ $: unknown;
37
+ $el: unknown;
38
+ url: string;
39
+ entryUrl: string;
40
+ ruleIndex: number;
41
+ matchIndex: number;
42
+ };
43
+ export type ReplaceElementFn = (ctx: ReplaceElementContext) => void | ReplaceAction | ReplaceAction[] | Promise<void | ReplaceAction | ReplaceAction[]>;
44
+ export type ReplaceElementFnWithQuery = {
45
+ query: string;
46
+ apply?: ApplyOptions;
47
+ run: ReplaceElementFn;
48
+ };
49
+ export type ReplaceElementsConfig = Array<ReplaceElementRule | ReplaceElementFn | ReplaceElementFnWithQuery>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export type { ChannelToken } from "./tokens.js";
2
+ export { createChannelToken } from "./tokens.js";
3
+ export type { MatchQuery, ReplaceAction, ApplyOptions, ReplaceElementRule, ReplaceElementContext, ReplaceElementFn, ReplaceElementFnWithQuery, ReplaceElementsConfig } from "./elements.js";
4
+ export type { DebugEvent } from "./well-known.js";
5
+ export { NETWORK, DEBUG } from "./well-known.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createChannelToken } from "./tokens.js";
2
+ export { NETWORK, DEBUG } from "./well-known.js";
@@ -0,0 +1,7 @@
1
+ export type ChannelToken<T> = {
2
+ readonly kind: "channel";
3
+ readonly id: `pagepocket:${string}`;
4
+ readonly name: string;
5
+ readonly __type?: (value: T) => T;
6
+ };
7
+ export declare const createChannelToken: <T>(name: string) => ChannelToken<T>;
package/dist/tokens.js ADDED
@@ -0,0 +1,7 @@
1
+ export const createChannelToken = (name) => {
2
+ return {
3
+ kind: "channel",
4
+ id: `pagepocket:${name}`,
5
+ name
6
+ };
7
+ };
@@ -0,0 +1,38 @@
1
+ export type NetworkEvent = {
2
+ type: "request";
3
+ requestId: string;
4
+ url: string;
5
+ method: string;
6
+ headers: Record<string, string>;
7
+ frameId?: string;
8
+ resourceType?: string;
9
+ initiator?: {
10
+ type?: string;
11
+ url?: string;
12
+ };
13
+ timestamp: number;
14
+ } | {
15
+ type: "response";
16
+ requestId: string;
17
+ url: string;
18
+ status: number;
19
+ statusText?: string;
20
+ headers: Record<string, string>;
21
+ mimeType?: string;
22
+ fromDiskCache?: boolean;
23
+ fromServiceWorker?: boolean;
24
+ timestamp: number;
25
+ body?: unknown;
26
+ } | {
27
+ type: "failed";
28
+ requestId: string;
29
+ url: string;
30
+ errorText: string;
31
+ timestamp: number;
32
+ };
33
+ export type DebugEvent = {
34
+ msg: string;
35
+ meta?: unknown;
36
+ };
37
+ export declare const NETWORK: import("./tokens.js").ChannelToken<NetworkEvent>;
38
+ export declare const DEBUG: import("./tokens.js").ChannelToken<DebugEvent>;
@@ -0,0 +1,3 @@
1
+ import { createChannelToken } from "./tokens.js";
2
+ export const NETWORK = createChannelToken("network@1");
3
+ export const DEBUG = createChannelToken("debug@1");
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@pagepocket/contracts",
3
+ "version": "0.8.0",
4
+ "description": "PagePocket v3 shared contracts: tokens and element patch types.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "license": "ISC",
18
+ "dependencies": {},
19
+ "devDependencies": {
20
+ "typescript": "^5.4.5"
21
+ },
22
+ "scripts": {
23
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
24
+ "test": "node -e \"process.exit(0)\""
25
+ }
26
+ }