@budarin/pluggable-serviceworker 1.0.8 → 1.0.10
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/package.json +1 -1
- package/.prettierignore +0 -3
- package/.prettierrc.mjs +0 -14
- package/.vscode/extensions.json +0 -26
- package/.vscode/launch.json +0 -20
- package/.vscode/settings.json +0 -164
- package/src/index.ts +0 -290
- package/tsconfig.json +0 -44
package/package.json
CHANGED
package/.prettierignore
DELETED
package/.prettierrc.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://prettier.io/docs/en/configuration.html
|
|
3
|
-
* @type {import("prettier").Config}
|
|
4
|
-
*/
|
|
5
|
-
const config = {
|
|
6
|
-
trailingComma: 'es5',
|
|
7
|
-
tabWidth: 4,
|
|
8
|
-
// semi: false,
|
|
9
|
-
singleQuote: true,
|
|
10
|
-
plugins: [],
|
|
11
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default config;
|
package/.vscode/extensions.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"recommendations": [
|
|
3
|
-
// "codeium.codeium",
|
|
4
|
-
"dbaeumer.vscode-eslint",
|
|
5
|
-
"esbenp.prettier-vscode",
|
|
6
|
-
"stylelint.vscode-stylelint",
|
|
7
|
-
"dsznajder.es7-react-js-snippets",
|
|
8
|
-
"ecmel.vscode-html-css",
|
|
9
|
-
"vitest.explorer",
|
|
10
|
-
"vscode-icons-team.vscode-icons",
|
|
11
|
-
"wayou.vscode-todo-highlight",
|
|
12
|
-
"felixfbecker.css-stacking-contexts",
|
|
13
|
-
// "formulahendry.auto-rename-tag",
|
|
14
|
-
"mhutchie.git-graph",
|
|
15
|
-
"ms-azuretools.vscode-docker",
|
|
16
|
-
"ms-playwright.playwrigh",
|
|
17
|
-
"naumovs.color-highlight",
|
|
18
|
-
"planbcoding.vscode-react-refactor",
|
|
19
|
-
"svetlanakost.typograf",
|
|
20
|
-
"viktorzetterstrom.non-breaking-space-highlighter",
|
|
21
|
-
"wallabyjs.wallaby-vscode",
|
|
22
|
-
"yoavbls.pretty-ts-errors",
|
|
23
|
-
"donjayamanne.githistory",
|
|
24
|
-
"pranaygp.vscode-css-peek"
|
|
25
|
-
]
|
|
26
|
-
}
|
package/.vscode/launch.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "node",
|
|
9
|
-
"request": "launch",
|
|
10
|
-
"name": "Launch Program",
|
|
11
|
-
"skipFiles": [
|
|
12
|
-
"<node_internals>/**"
|
|
13
|
-
],
|
|
14
|
-
"program": "${workspaceFolder}\\src\\sw\\helpers\\handleFetch\\index.ts",
|
|
15
|
-
"outFiles": [
|
|
16
|
-
"${workspaceFolder}/**/*.js"
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|
package/.vscode/settings.json
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// explorer
|
|
3
|
-
"explorer.autoReveal": true,
|
|
4
|
-
"explorer.incrementalNaming": "smart",
|
|
5
|
-
"debug.openExplorerOnEnd": true,
|
|
6
|
-
|
|
7
|
-
// editor
|
|
8
|
-
"editor.fontLigatures": true,
|
|
9
|
-
"editor.mouseWheelZoom": true,
|
|
10
|
-
"editor.smoothScrolling": true,
|
|
11
|
-
"editor.cursorSmoothCaretAnimation": "on",
|
|
12
|
-
"editor.minimap.enabled": false,
|
|
13
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
14
|
-
"editor.formatOnSave": true,
|
|
15
|
-
"editor.formatOnPaste": true,
|
|
16
|
-
"editor.language.colorizedBracketPairs": [
|
|
17
|
-
[
|
|
18
|
-
"(",
|
|
19
|
-
")"
|
|
20
|
-
],
|
|
21
|
-
[
|
|
22
|
-
"[",
|
|
23
|
-
"]"
|
|
24
|
-
],
|
|
25
|
-
[
|
|
26
|
-
"{",
|
|
27
|
-
"}"
|
|
28
|
-
]
|
|
29
|
-
],
|
|
30
|
-
"editor.suggestSelection": "first",
|
|
31
|
-
"editor.codeActionsOnSave": {
|
|
32
|
-
"source.fixAll": "explicit",
|
|
33
|
-
"source.organizeImports": "never"
|
|
34
|
-
},
|
|
35
|
-
"editor.guides.bracketPairs": true,
|
|
36
|
-
"editor.guides.highlightActiveBracketPair": false,
|
|
37
|
-
"editor.fontFamily": "Consolas, Monaco, Menlo,'Courier New', monospace",
|
|
38
|
-
|
|
39
|
-
// files
|
|
40
|
-
"files.autoSave": "onFocusChange",
|
|
41
|
-
"files.insertFinalNewline": true,
|
|
42
|
-
"files.trimFinalNewlines": true,
|
|
43
|
-
"files.trimTrailingWhitespace": true,
|
|
44
|
-
"files.eol": "\n",
|
|
45
|
-
|
|
46
|
-
// git
|
|
47
|
-
"git.enableSmartCommit": true,
|
|
48
|
-
"git.confirmSync": false,
|
|
49
|
-
"git.autofetch": true,
|
|
50
|
-
"git.autofetchPeriod": 60,
|
|
51
|
-
// "git.branchProtection": ["master"],
|
|
52
|
-
"git.checkoutType": [
|
|
53
|
-
"local",
|
|
54
|
-
"remote"
|
|
55
|
-
],
|
|
56
|
-
"git.ignoreRebaseWarning": true,
|
|
57
|
-
"git.inputValidationSubjectLength": 100,
|
|
58
|
-
"git.inputValidationLength": 200,
|
|
59
|
-
|
|
60
|
-
// ts/javascript
|
|
61
|
-
// "typescript.surveys.enabled": false,
|
|
62
|
-
"javascript.suggestionActions.enabled": false,
|
|
63
|
-
"typescript.tsdk": "./node_modules/typescript/lib",
|
|
64
|
-
"typescript.updateImportsOnFileMove.enabled": "always",
|
|
65
|
-
"typescript.preferences.importModuleSpecifier": "shortest",
|
|
66
|
-
"javascript.updateImportsOnFileMove.enabled": "always",
|
|
67
|
-
"typescript.format.semicolons": "insert",
|
|
68
|
-
"javascript.format.semicolons": "insert",
|
|
69
|
-
|
|
70
|
-
// prettier
|
|
71
|
-
"prettier.enable": true,
|
|
72
|
-
"json.format.enable": true,
|
|
73
|
-
"prettier.configPath": ".prettierrc.mjs",
|
|
74
|
-
"prettier.experimentalTernaries": true,
|
|
75
|
-
"prettier.enableDebugLogs": true,
|
|
76
|
-
"prettier.prettierPath": "./node_modules/prettier",
|
|
77
|
-
"prettier.htmlWhitespaceSensitivity": "strict",
|
|
78
|
-
"[json]": {
|
|
79
|
-
"editor.formatOnSave": true
|
|
80
|
-
},
|
|
81
|
-
"[css]": {
|
|
82
|
-
"editor.formatOnSave": true,
|
|
83
|
-
"editor.defaultFormatter": "vscode.css-language-features"
|
|
84
|
-
},
|
|
85
|
-
"[html]": {
|
|
86
|
-
"editor.formatOnSave": true,
|
|
87
|
-
"editor.defaultFormatter": "vscode.html-language-features"
|
|
88
|
-
},
|
|
89
|
-
"[jsonc]": {
|
|
90
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
91
|
-
},
|
|
92
|
-
"[xml]": {
|
|
93
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
94
|
-
},
|
|
95
|
-
"[svg]": {
|
|
96
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
97
|
-
},
|
|
98
|
-
"[typescriptreact]": {
|
|
99
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
100
|
-
},
|
|
101
|
-
"[typescript]": {
|
|
102
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
103
|
-
},
|
|
104
|
-
"[javascript]": {
|
|
105
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
106
|
-
},
|
|
107
|
-
"[javascriptreact]": {
|
|
108
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
109
|
-
},
|
|
110
|
-
"[markdown]": {
|
|
111
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
// workbench
|
|
115
|
-
"workbench.iconTheme": "vscode-icons",
|
|
116
|
-
"workbench.colorTheme": "Default Dark+",
|
|
117
|
-
"workbench.externalBrowser": "chrome",
|
|
118
|
-
"workbench.colorCustomizations": {},
|
|
119
|
-
|
|
120
|
-
// terminal
|
|
121
|
-
"terminal.integrated.defaultProfile.windows": "Git Bash",
|
|
122
|
-
"terminal.integrated.cursorBlinking": true,
|
|
123
|
-
"terminal.integrated.fontFamily": "Consolas, 'Courier New', monospace",
|
|
124
|
-
"terminal.integrated.minimumContrastRatio": 4.5,
|
|
125
|
-
"terminal.integrated.smoothScrolling": true,
|
|
126
|
-
"terminal.integrated.profiles.windows": {
|
|
127
|
-
"Bash": {
|
|
128
|
-
"path": "C:\\Program Files\\Git\\bin\\bash.exe",
|
|
129
|
-
"args": []
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
"terminal.integrated.scrollback": 500000,
|
|
133
|
-
"terminal.integrated.enablePersistentSessions": false,
|
|
134
|
-
"workbench.tree.enableStickyScroll": false,
|
|
135
|
-
"editor.stickyScroll.scrollWithEditor": false,
|
|
136
|
-
"editor.stickyScroll.enabled": false,
|
|
137
|
-
"accessibility.signals.terminalBell": {
|
|
138
|
-
"sound": "on"
|
|
139
|
-
},
|
|
140
|
-
"terminal.integrated.enableVisualBell": true,
|
|
141
|
-
|
|
142
|
-
// npm scripts
|
|
143
|
-
"npm.scriptExplorerAction": "run",
|
|
144
|
-
|
|
145
|
-
// emmet
|
|
146
|
-
"emmet.includeLanguages": {
|
|
147
|
-
"postcss": "css",
|
|
148
|
-
"javascript": "javascriptreact",
|
|
149
|
-
"typescript": "typescriptreact"
|
|
150
|
-
},
|
|
151
|
-
"emmet.showSuggestionsAsSnippets": true,
|
|
152
|
-
|
|
153
|
-
"notebook.defaultFormatter": "esbenp.prettier-vscode",
|
|
154
|
-
"window.zoomLevel": 0,
|
|
155
|
-
|
|
156
|
-
// extensions
|
|
157
|
-
"reactSnippets.settings.prettierEnabled": true,
|
|
158
|
-
|
|
159
|
-
"stylelint.configBasedir": "./",
|
|
160
|
-
"stylelint.configFile": "./stylelint.config.mjs",
|
|
161
|
-
"stylelint.packageManager": "pnpm",
|
|
162
|
-
|
|
163
|
-
"javascript.preferences.importModuleSpecifier": "non-relative",
|
|
164
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
export enum ServiceWorkerErrorType {
|
|
2
|
-
ERROR = 'error',
|
|
3
|
-
MESSAGE_ERROR = 'messageerror',
|
|
4
|
-
UNHANDLED_REJECTION = 'unhandledrejection',
|
|
5
|
-
REJECTION_HANDLED = 'rejectionhandled',
|
|
6
|
-
PLUGIN_ERROR = 'plugin_error',
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface SyncEvent extends ExtendableEvent {
|
|
10
|
-
readonly tag: string;
|
|
11
|
-
readonly lastChance: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface PeriodicSyncEvent extends ExtendableEvent {
|
|
15
|
-
readonly tag: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Extend ServiceWorkerGlobalScope to include sync events
|
|
19
|
-
declare global {
|
|
20
|
-
interface ServiceWorkerGlobalScopeEventMap {
|
|
21
|
-
sync: SyncEvent;
|
|
22
|
-
periodicsync: PeriodicSyncEvent;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface ServiceWorkerEventHandlers {
|
|
27
|
-
install?: (event: ExtendableEvent) => void | Promise<void>;
|
|
28
|
-
activate?: (event: ExtendableEvent) => void | Promise<void>;
|
|
29
|
-
fetch?: (event: FetchEvent) => Promise<Response | null>;
|
|
30
|
-
message?: (event: MessageEvent) => void;
|
|
31
|
-
sync?: (event: SyncEvent) => void | Promise<void>;
|
|
32
|
-
periodicsync?: (event: PeriodicSyncEvent) => void | Promise<void>;
|
|
33
|
-
push?: (event: PushEvent) => void | Promise<void>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface ServiceWorkerPlugin extends ServiceWorkerEventHandlers {
|
|
37
|
-
name: string;
|
|
38
|
-
order?: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface ServiceWorkerConfig {
|
|
42
|
-
plugins?: ServiceWorkerPlugin[];
|
|
43
|
-
onError?: (
|
|
44
|
-
error: Error | any,
|
|
45
|
-
event: Event,
|
|
46
|
-
errorType?: ServiceWorkerErrorType
|
|
47
|
-
) => void;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
type FetchResponse = Promise<Response | null>;
|
|
51
|
-
|
|
52
|
-
export function createEventHandlers(
|
|
53
|
-
plugins: ServiceWorkerPlugin[],
|
|
54
|
-
config: ServiceWorkerConfig = {}
|
|
55
|
-
): {
|
|
56
|
-
install: (event: ExtendableEvent) => void;
|
|
57
|
-
activate: (event: ExtendableEvent) => void;
|
|
58
|
-
fetch: (event: FetchEvent) => void;
|
|
59
|
-
message: (event: MessageEvent) => void;
|
|
60
|
-
sync: (event: SyncEvent) => void;
|
|
61
|
-
periodicsync: (event: PeriodicSyncEvent) => void;
|
|
62
|
-
push: (event: PushEvent) => void;
|
|
63
|
-
error: (event: ErrorEvent) => void;
|
|
64
|
-
messageerror: (event: MessageEvent) => void;
|
|
65
|
-
unhandledrejection: (event: PromiseRejectionEvent) => void;
|
|
66
|
-
rejectionhandled: (event: PromiseRejectionEvent) => void;
|
|
67
|
-
} {
|
|
68
|
-
const handlers = {
|
|
69
|
-
install: [] as ((event: ExtendableEvent) => void | Promise<void>)[],
|
|
70
|
-
activate: [] as ((event: ExtendableEvent) => void | Promise<void>)[],
|
|
71
|
-
fetch: [] as ((event: FetchEvent) => FetchResponse)[],
|
|
72
|
-
message: [] as ((event: MessageEvent) => void)[],
|
|
73
|
-
sync: [] as ((event: SyncEvent) => void | Promise<void>)[],
|
|
74
|
-
periodicsync: [] as ((
|
|
75
|
-
event: PeriodicSyncEvent
|
|
76
|
-
) => void | Promise<void>)[],
|
|
77
|
-
push: [] as ((event: PushEvent) => void | Promise<void>)[],
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// Сортировка плагинов по порядку выполнения:
|
|
81
|
-
// 1. Сначала выполняются ВСЕ плагины без order (undefined) в том порядке, в котором они были добавлены
|
|
82
|
-
// 2. Затем выполняются плагины с order в порядке возрастания значений order
|
|
83
|
-
const sortedPlugins = [
|
|
84
|
-
...plugins.filter((plugin) => plugin.order === undefined),
|
|
85
|
-
...plugins
|
|
86
|
-
.filter((plugin) => plugin.order !== undefined)
|
|
87
|
-
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)),
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
sortedPlugins.forEach((plugin) => {
|
|
91
|
-
if (plugin.install) handlers.install.push(plugin.install);
|
|
92
|
-
if (plugin.activate) handlers.activate.push(plugin.activate);
|
|
93
|
-
if (plugin.fetch) handlers.fetch.push(plugin.fetch);
|
|
94
|
-
if (plugin.message) handlers.message.push(plugin.message);
|
|
95
|
-
if (plugin.sync) handlers.sync.push(plugin.sync);
|
|
96
|
-
if (plugin.periodicsync)
|
|
97
|
-
handlers.periodicsync.push(plugin.periodicsync);
|
|
98
|
-
if (plugin.push) handlers.push.push(plugin.push);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
install: (event: ExtendableEvent): void => {
|
|
103
|
-
event.waitUntil(
|
|
104
|
-
Promise.all(
|
|
105
|
-
handlers.install.map((handler) =>
|
|
106
|
-
Promise.resolve(handler(event)).catch(
|
|
107
|
-
(error: unknown) =>
|
|
108
|
-
config.onError?.(
|
|
109
|
-
error as Error,
|
|
110
|
-
event,
|
|
111
|
-
ServiceWorkerErrorType.PLUGIN_ERROR
|
|
112
|
-
)
|
|
113
|
-
)
|
|
114
|
-
)
|
|
115
|
-
)
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
activate: (event: ExtendableEvent): void => {
|
|
120
|
-
event.waitUntil(
|
|
121
|
-
Promise.all(
|
|
122
|
-
handlers.activate.map((handler) =>
|
|
123
|
-
Promise.resolve(handler(event)).catch(
|
|
124
|
-
(error: unknown) =>
|
|
125
|
-
config.onError?.(
|
|
126
|
-
error as Error,
|
|
127
|
-
event,
|
|
128
|
-
ServiceWorkerErrorType.PLUGIN_ERROR
|
|
129
|
-
)
|
|
130
|
-
)
|
|
131
|
-
)
|
|
132
|
-
)
|
|
133
|
-
);
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
fetch: (event: FetchEvent): void => {
|
|
137
|
-
event.respondWith(
|
|
138
|
-
(async (): Promise<Response> => {
|
|
139
|
-
for (const handler of handlers.fetch) {
|
|
140
|
-
try {
|
|
141
|
-
const result = await handler(event);
|
|
142
|
-
if (result) {
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
} catch (error) {
|
|
146
|
-
config.onError?.(
|
|
147
|
-
error as Error,
|
|
148
|
-
event,
|
|
149
|
-
ServiceWorkerErrorType.PLUGIN_ERROR
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return fetch(event.request);
|
|
154
|
-
})()
|
|
155
|
-
);
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
message: (event: MessageEvent): void => {
|
|
159
|
-
handlers.message.forEach((handler) => {
|
|
160
|
-
try {
|
|
161
|
-
handler(event);
|
|
162
|
-
} catch (error) {
|
|
163
|
-
config.onError?.(error as Error, event);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
sync: (event: SyncEvent): void => {
|
|
169
|
-
event.waitUntil(
|
|
170
|
-
Promise.all(
|
|
171
|
-
handlers.sync.map((handler) =>
|
|
172
|
-
Promise.resolve(handler(event)).catch(
|
|
173
|
-
(error: unknown) =>
|
|
174
|
-
config.onError?.(
|
|
175
|
-
error as Error,
|
|
176
|
-
event,
|
|
177
|
-
ServiceWorkerErrorType.PLUGIN_ERROR
|
|
178
|
-
)
|
|
179
|
-
)
|
|
180
|
-
)
|
|
181
|
-
)
|
|
182
|
-
);
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
periodicsync: (event: PeriodicSyncEvent): void => {
|
|
186
|
-
event.waitUntil(
|
|
187
|
-
Promise.all(
|
|
188
|
-
handlers.periodicsync.map((handler) =>
|
|
189
|
-
Promise.resolve(handler(event)).catch(
|
|
190
|
-
(error: unknown) =>
|
|
191
|
-
config.onError?.(
|
|
192
|
-
error as Error,
|
|
193
|
-
event,
|
|
194
|
-
ServiceWorkerErrorType.PLUGIN_ERROR
|
|
195
|
-
)
|
|
196
|
-
)
|
|
197
|
-
)
|
|
198
|
-
)
|
|
199
|
-
);
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
push: (event: PushEvent): void => {
|
|
203
|
-
event.waitUntil(
|
|
204
|
-
(async (): Promise<void> => {
|
|
205
|
-
for (const handler of handlers.push) {
|
|
206
|
-
try {
|
|
207
|
-
await Promise.resolve(handler(event));
|
|
208
|
-
} catch (error) {
|
|
209
|
-
config.onError?.(
|
|
210
|
-
error as Error,
|
|
211
|
-
event,
|
|
212
|
-
ServiceWorkerErrorType.PLUGIN_ERROR
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
})()
|
|
217
|
-
);
|
|
218
|
-
},
|
|
219
|
-
|
|
220
|
-
error: (event: ErrorEvent): void => {
|
|
221
|
-
try {
|
|
222
|
-
config.onError?.(
|
|
223
|
-
event.error,
|
|
224
|
-
event,
|
|
225
|
-
ServiceWorkerErrorType.ERROR
|
|
226
|
-
);
|
|
227
|
-
} catch (error) {
|
|
228
|
-
console.error('Error in error handler:', error);
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
|
|
232
|
-
messageerror: (event: MessageEvent): void => {
|
|
233
|
-
try {
|
|
234
|
-
config.onError?.(
|
|
235
|
-
event.data,
|
|
236
|
-
event,
|
|
237
|
-
ServiceWorkerErrorType.MESSAGE_ERROR
|
|
238
|
-
);
|
|
239
|
-
} catch (error) {
|
|
240
|
-
console.error('Error in messageerror handler:', error);
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
unhandledrejection: (event: PromiseRejectionEvent): void => {
|
|
245
|
-
try {
|
|
246
|
-
config.onError?.(
|
|
247
|
-
event.reason,
|
|
248
|
-
event,
|
|
249
|
-
ServiceWorkerErrorType.UNHANDLED_REJECTION
|
|
250
|
-
);
|
|
251
|
-
} catch (error) {
|
|
252
|
-
console.error('Error in unhandledrejection handler:', error);
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
|
|
256
|
-
rejectionhandled: (event: PromiseRejectionEvent): void => {
|
|
257
|
-
try {
|
|
258
|
-
config.onError?.(
|
|
259
|
-
event.reason,
|
|
260
|
-
event,
|
|
261
|
-
ServiceWorkerErrorType.REJECTION_HANDLED
|
|
262
|
-
);
|
|
263
|
-
} catch (error) {
|
|
264
|
-
console.error('Error in rejectionhandled handler:', error);
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export function initializeServiceWorker(
|
|
271
|
-
plugins: ServiceWorkerPlugin[],
|
|
272
|
-
config?: ServiceWorkerConfig
|
|
273
|
-
): void {
|
|
274
|
-
const handlers = createEventHandlers(plugins, config);
|
|
275
|
-
|
|
276
|
-
// Регистрируем стандартные обработчики событий Service Worker
|
|
277
|
-
self.addEventListener('install', handlers.install);
|
|
278
|
-
self.addEventListener('activate', handlers.activate);
|
|
279
|
-
self.addEventListener('fetch', handlers.fetch);
|
|
280
|
-
self.addEventListener('message', handlers.message);
|
|
281
|
-
self.addEventListener('sync', handlers.sync);
|
|
282
|
-
self.addEventListener('periodicsync', handlers.periodicsync);
|
|
283
|
-
self.addEventListener('push', handlers.push);
|
|
284
|
-
|
|
285
|
-
// Регистрируем глобальные обработчики ошибок
|
|
286
|
-
self.addEventListener('error', handlers.error);
|
|
287
|
-
self.addEventListener('messageerror', handlers.messageerror);
|
|
288
|
-
self.addEventListener('unhandledrejection', handlers.unhandledrejection);
|
|
289
|
-
self.addEventListener('rejectionhandled', handlers.rejectionhandled);
|
|
290
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
// File Layout
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
|
|
8
|
-
// Environment Settings
|
|
9
|
-
// See also https://aka.ms/tsconfig/module
|
|
10
|
-
"module": "nodenext",
|
|
11
|
-
"target": "esnext",
|
|
12
|
-
// For nodejs:
|
|
13
|
-
"lib": ["esnext"],
|
|
14
|
-
"types": ["node", "serviceworker", "web"],
|
|
15
|
-
// and npm install -D @types/node
|
|
16
|
-
|
|
17
|
-
// Other Outputs
|
|
18
|
-
"sourceMap": true,
|
|
19
|
-
"declaration": true,
|
|
20
|
-
"declarationMap": true,
|
|
21
|
-
|
|
22
|
-
// Stricter Typechecking Options
|
|
23
|
-
"noUncheckedIndexedAccess": true,
|
|
24
|
-
"exactOptionalPropertyTypes": true,
|
|
25
|
-
|
|
26
|
-
// Style Options
|
|
27
|
-
"noImplicitReturns": true,
|
|
28
|
-
"noImplicitOverride": true,
|
|
29
|
-
"noUnusedLocals": true,
|
|
30
|
-
"noUnusedParameters": true,
|
|
31
|
-
"noFallthroughCasesInSwitch": true,
|
|
32
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
33
|
-
|
|
34
|
-
// Recommended Options
|
|
35
|
-
"strict": true,
|
|
36
|
-
"jsx": "react-jsx",
|
|
37
|
-
"verbatimModuleSyntax": true,
|
|
38
|
-
"isolatedModules": true,
|
|
39
|
-
"noUncheckedSideEffectImports": true,
|
|
40
|
-
"moduleDetection": "force",
|
|
41
|
-
"skipLibCheck": true,
|
|
42
|
-
"removeComments": true
|
|
43
|
-
}
|
|
44
|
-
}
|