Skip to content

Commit a4d3ea3

Browse files
authored
Merge pull request #437 from saschanaz/push
Add push/sync types
2 parents 3bdb711 + 8199fdd commit a4d3ea3

6 files changed

+155
-8
lines changed

baselines/dom.generated.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,16 +1114,22 @@ interface ProgressEventInit extends EventInit {
11141114
}
11151115

11161116
interface PushEventInit extends ExtendableEventInit {
1117-
data?: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | string | null;
1117+
data?: PushMessageDataInit;
11181118
}
11191119

11201120
interface PushSubscriptionChangeInit extends ExtendableEventInit {
11211121
newSubscription?: PushSubscription;
11221122
oldSubscription?: PushSubscription;
11231123
}
11241124

1125+
interface PushSubscriptionJSON {
1126+
endpoint?: string;
1127+
expirationTime?: number | null;
1128+
keys?: Record<string, string>;
1129+
}
1130+
11251131
interface PushSubscriptionOptionsInit {
1126-
applicationServerKey?: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | string | null;
1132+
applicationServerKey?: BufferSource | string;
11271133
userVisibleOnly?: boolean;
11281134
}
11291135

@@ -10458,7 +10464,7 @@ interface PushSubscription {
1045810464
readonly expirationTime: number | null;
1045910465
readonly options: PushSubscriptionOptions;
1046010466
getKey(name: PushEncryptionKeyName): ArrayBuffer | null;
10461-
toJSON(): any;
10467+
toJSON(): PushSubscriptionJSON;
1046210468
unsubscribe(): Promise<boolean>;
1046310469
}
1046410470

@@ -16480,6 +16486,7 @@ type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStrea
1648016486
type RequestInfo = Request | string;
1648116487
type DOMHighResTimeStamp = number;
1648216488
type PerformanceEntryList = PerformanceEntry[];
16489+
type PushMessageDataInit = BufferSource | string;
1648316490
type BufferSource = ArrayBufferView | ArrayBuffer;
1648416491
type DOMTimeStamp = number;
1648516492
type FormDataEntryValue = File | string;
@@ -16570,7 +16577,7 @@ type PanningModelType = "equalpower" | "HRTF";
1657016577
type PaymentComplete = "success" | "fail" | "unknown";
1657116578
type PaymentShippingType = "shipping" | "delivery" | "pickup";
1657216579
type PushEncryptionKeyName = "p256dh" | "auth";
16573-
type PushPermissionState = "granted" | "denied" | "prompt";
16580+
type PushPermissionState = "denied" | "granted" | "prompt";
1657416581
type RTCBundlePolicy = "balanced" | "max-compat" | "max-bundle";
1657516582
type RTCDataChannelState = "connecting" | "open" | "closing" | "closed";
1657616583
type RTCDegradationPreference = "maintain-framerate" | "maintain-resolution" | "balanced";

baselines/webworker.generated.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,22 @@ interface ProgressEventInit extends EventInit {
128128
}
129129

130130
interface PushEventInit extends ExtendableEventInit {
131-
data?: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | string | null;
131+
data?: PushMessageDataInit;
132132
}
133133

134134
interface PushSubscriptionChangeInit extends ExtendableEventInit {
135135
newSubscription?: PushSubscription;
136136
oldSubscription?: PushSubscription;
137137
}
138138

139+
interface PushSubscriptionJSON {
140+
endpoint?: string;
141+
expirationTime?: number | null;
142+
keys?: Record<string, string>;
143+
}
144+
139145
interface PushSubscriptionOptionsInit {
140-
applicationServerKey?: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | string | null;
146+
applicationServerKey?: BufferSource | string;
141147
userVisibleOnly?: boolean;
142148
}
143149

@@ -1217,7 +1223,7 @@ interface PushSubscription {
12171223
readonly expirationTime: number | null;
12181224
readonly options: PushSubscriptionOptions;
12191225
getKey(name: PushEncryptionKeyName): ArrayBuffer | null;
1220-
toJSON(): any;
1226+
toJSON(): PushSubscriptionJSON;
12211227
unsubscribe(): Promise<boolean>;
12221228
}
12231229

@@ -1775,6 +1781,7 @@ type HeadersInit = Headers | string[][] | Record<string, string>;
17751781
type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStream | string;
17761782
type RequestInfo = Request | string;
17771783
type PerformanceEntryList = PerformanceEntry[];
1784+
type PushMessageDataInit = BufferSource | string;
17781785
type BufferSource = ArrayBufferView | ArrayBuffer;
17791786
type FormDataEntryValue = File | string;
17801787
type IDBValidKey = number | string | Date | BufferSource | IDBArrayKey;
@@ -1811,7 +1818,7 @@ type MediaKeyStatus = "usable" | "expired" | "output-downscaled" | "output-not-a
18111818
type NotificationDirection = "auto" | "ltr" | "rtl";
18121819
type NotificationPermission = "default" | "denied" | "granted";
18131820
type PushEncryptionKeyName = "p256dh" | "auth";
1814-
type PushPermissionState = "granted" | "denied" | "prompt";
1821+
type PushPermissionState = "denied" | "granted" | "prompt";
18151822
type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "origin-only" | "origin-when-cross-origin" | "unsafe-url";
18161823
type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached";
18171824
type RequestCredentials = "omit" | "same-origin" | "include";

inputfiles/idl/Push.widl

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
[SecureContext]
2+
partial interface ServiceWorkerRegistration {
3+
readonly attribute PushManager pushManager;
4+
};
5+
6+
[Exposed=(Window,Worker),
7+
SecureContext]
8+
interface PushManager {
9+
[SameObject]
10+
static readonly attribute FrozenArray<DOMString> supportedContentEncodings;
11+
12+
Promise<PushSubscription> subscribe(optional PushSubscriptionOptionsInit options);
13+
Promise<PushSubscription?> getSubscription();
14+
Promise<PushPermissionState> permissionState(optional PushSubscriptionOptionsInit options);
15+
};
16+
17+
dictionary PushSubscriptionOptionsInit {
18+
boolean userVisibleOnly = false;
19+
(BufferSource or DOMString)? applicationServerKey = null;
20+
};
21+
22+
[Exposed=(Window,Worker),
23+
SecureContext]
24+
interface PushSubscriptionOptions {
25+
readonly attribute boolean userVisibleOnly;
26+
[SameObject]
27+
readonly attribute ArrayBuffer? applicationServerKey;
28+
};
29+
30+
[Exposed=(Window,Worker),
31+
SecureContext]
32+
interface PushSubscription {
33+
readonly attribute USVString endpoint;
34+
readonly attribute DOMTimeStamp? expirationTime;
35+
[SameObject]
36+
readonly attribute PushSubscriptionOptions options;
37+
ArrayBuffer? getKey(PushEncryptionKeyName name);
38+
Promise<boolean> unsubscribe();
39+
40+
PushSubscriptionJSON toJSON();
41+
};
42+
43+
dictionary PushSubscriptionJSON {
44+
USVString endpoint;
45+
DOMTimeStamp? expirationTime;
46+
record<DOMString, USVString> keys;
47+
};
48+
49+
enum PushEncryptionKeyName {
50+
"p256dh",
51+
"auth"
52+
};
53+
54+
[Exposed=ServiceWorker,
55+
SecureContext]
56+
interface PushMessageData {
57+
ArrayBuffer arrayBuffer();
58+
Blob blob();
59+
any json();
60+
USVString text();
61+
};
62+
63+
[Exposed=ServiceWorker,
64+
SecureContext]
65+
partial interface ServiceWorkerGlobalScope {
66+
attribute EventHandler onpush;
67+
attribute EventHandler onpushsubscriptionchange;
68+
};
69+
70+
typedef (BufferSource or USVString) PushMessageDataInit;
71+
72+
dictionary PushEventInit : ExtendableEventInit {
73+
PushMessageDataInit data;
74+
};
75+
76+
[Constructor(DOMString type, optional PushEventInit eventInitDict),
77+
Exposed=ServiceWorker,
78+
SecureContext]
79+
interface PushEvent : ExtendableEvent {
80+
readonly attribute PushMessageData? data;
81+
};
82+
83+
dictionary PushSubscriptionChangeInit : ExtendableEventInit {
84+
PushSubscription newSubscription = null;
85+
PushSubscription oldSubscription = null;
86+
};
87+
88+
[Constructor(DOMString type, optional PushSubscriptionChangeInit eventInitDict),
89+
Exposed=ServiceWorker,
90+
SecureContext]
91+
interface PushSubscriptionChangeEvent : ExtendableEvent {
92+
readonly attribute PushSubscription? newSubscription;
93+
readonly attribute PushSubscription? oldSubscription;
94+
};
95+
96+
enum PushPermissionState {
97+
"denied",
98+
"granted",
99+
"prompt",
100+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
partial interface ServiceWorkerRegistration {
2+
readonly attribute SyncManager sync;
3+
};
4+
5+
[Exposed=(Window,Worker)]
6+
interface SyncManager {
7+
Promise<void> register(DOMString tag);
8+
Promise<sequence<DOMString>> getTags();
9+
};
10+
11+
partial interface ServiceWorkerGlobalScope {
12+
attribute EventHandler onsync;
13+
};
14+
15+
[Constructor(DOMString type, SyncEventInit init), Exposed=ServiceWorker]
16+
interface SyncEvent : ExtendableEvent {
17+
readonly attribute DOMString tag;
18+
readonly attribute boolean lastChance;
19+
};
20+
21+
dictionary SyncEventInit : ExtendableEventInit {
22+
required DOMString tag;
23+
boolean lastChance = false;
24+
};

inputfiles/idlSources.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
"url": "https://w3c.github.io/performance-timeline/",
2828
"title": "Performance Timeline"
2929
},
30+
{
31+
"url": "https://www.w3.org/TR/push-api/",
32+
"title": "Push"
33+
},
3034
{
3135
"url": "https://w3c.github.io/resource-timing/",
3236
"title": "Resource Timing"
@@ -39,6 +43,10 @@
3943
"url": "https://www.w3.org/TR/user-timing-2/",
4044
"title": "User Timing"
4145
},
46+
{
47+
"url": "https://wicg.github.io/BackgroundSync/spec/",
48+
"title": "Web Background Synchronization"
49+
},
4250
{
4351
"url": "https://heycam.github.io/webidl/",
4452
"title": "Web IDL"

inputfiles/knownWorkerTypes.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"ProgressEvent",
7171
"PushManager",
7272
"PushSubscription",
73+
"PushSubscriptionJSON",
7374
"PushSubscriptionOptions",
7475
"ReadableStream",
7576
"ReadableStreamReader",

0 commit comments

Comments
 (0)