astro-integration-pocketbase 2.1.5 → 2.1.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 +28 -30
- package/src/core/refresh-collections-realtime.ts +5 -2
- package/src/core/refresh-collections.ts +1 -0
- package/src/pocketbase-integration.ts +1 -1
- package/src/toolbar/dom/create-entity.ts +5 -3
- package/src/toolbar/dom/create-header.ts +10 -6
- package/src/toolbar/init-toolbar.ts +5 -3
- package/src/utils/get-superuser-token.ts +3 -1
- package/src/utils/map-collections-to-watch.ts +3 -3
package/package.json
CHANGED
|
@@ -1,66 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-integration-pocketbase",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"description": "An Astro integration to support developers working with astro-loader-pocketbase.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
7
7
|
"astro-integration",
|
|
8
|
-
"pocketbase",
|
|
9
|
-
"withastro",
|
|
10
|
-
"devtools",
|
|
11
8
|
"dev-overlay",
|
|
12
9
|
"dev-toolbar",
|
|
13
|
-
"
|
|
10
|
+
"devtools",
|
|
11
|
+
"pocketbase",
|
|
12
|
+
"tooling",
|
|
13
|
+
"withastro"
|
|
14
14
|
],
|
|
15
15
|
"homepage": "https://github.com/pawcoding/astro-integration-pocketbase",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/pawcoding/astro-integration-pocketbase/issues"
|
|
18
18
|
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Luis Wolf <development@pawcode.de> (https://pawcode.de)",
|
|
19
21
|
"repository": {
|
|
20
22
|
"type": "git",
|
|
21
23
|
"url": "git+https://github.com/pawcoding/astro-integration-pocketbase.git"
|
|
22
24
|
},
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"author": "Luis Wolf <development@pawcode.de> (https://pawcode.de)",
|
|
25
|
-
"type": "module",
|
|
26
|
-
"exports": {
|
|
27
|
-
".": "./index.ts"
|
|
28
|
-
},
|
|
29
25
|
"files": [
|
|
30
26
|
"src",
|
|
31
27
|
"index.ts"
|
|
32
28
|
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./index.ts"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"provenance": true
|
|
36
|
+
},
|
|
33
37
|
"scripts": {
|
|
34
|
-
"format": "
|
|
35
|
-
"format:check": "
|
|
38
|
+
"format": "oxfmt",
|
|
39
|
+
"format:check": "oxfmt --check",
|
|
36
40
|
"lint": "oxlint --type-aware",
|
|
37
41
|
"lint:fix": "oxlint --type-aware --fix",
|
|
38
42
|
"prepare": "husky",
|
|
39
|
-
"typecheck": "
|
|
43
|
+
"typecheck": "tsc --noEmit"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@commitlint/cli": "20.
|
|
43
|
-
"@commitlint/config-conventional": "20.
|
|
44
|
-
"@types/node": "24.
|
|
45
|
-
"astro": "5.
|
|
46
|
+
"@commitlint/cli": "20.4.4",
|
|
47
|
+
"@commitlint/config-conventional": "20.4.4",
|
|
48
|
+
"@types/node": "24.12.0",
|
|
49
|
+
"astro": "5.18.1",
|
|
46
50
|
"eventsource": "4.1.0",
|
|
47
|
-
"globals": "
|
|
51
|
+
"globals": "17.4.0",
|
|
48
52
|
"husky": "9.1.7",
|
|
49
|
-
"lint-staged": "16.
|
|
50
|
-
"
|
|
51
|
-
"oxlint
|
|
52
|
-
"
|
|
53
|
-
"prettier-plugin-organize-imports": "4.3.0",
|
|
54
|
-
"prettier-plugin-packagejson": "2.5.19",
|
|
53
|
+
"lint-staged": "16.3.4",
|
|
54
|
+
"oxfmt": "0.40.0",
|
|
55
|
+
"oxlint": "1.55.0",
|
|
56
|
+
"oxlint-tsgolint": "0.16.0",
|
|
55
57
|
"typescript": "5.9.3"
|
|
56
58
|
},
|
|
57
59
|
"peerDependencies": {
|
|
58
60
|
"astro": "^5.0.0",
|
|
59
61
|
"eventsource": "^4.0.0"
|
|
60
62
|
},
|
|
61
|
-
"packageManager": "npm@11.
|
|
62
|
-
"publishConfig": {
|
|
63
|
-
"access": "public",
|
|
64
|
-
"provenance": true
|
|
65
|
-
}
|
|
63
|
+
"packageManager": "npm@11.11.1"
|
|
66
64
|
}
|
|
@@ -28,6 +28,7 @@ export function refreshCollectionsRealtime(
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Check if EventSource is available
|
|
31
|
+
// oxlint-disable-next-line no-unnecessary-condition
|
|
31
32
|
if (!EventSource) {
|
|
32
33
|
logger.warn(
|
|
33
34
|
"EventSource is not available, skipping subscription to PocketBase realtime API.\n" +
|
|
@@ -42,7 +43,8 @@ export function refreshCollectionsRealtime(
|
|
|
42
43
|
refreshEnabled = enabled;
|
|
43
44
|
});
|
|
44
45
|
|
|
45
|
-
const
|
|
46
|
+
const eventSourceUrl = new URL("api/realtime", options.url).href;
|
|
47
|
+
const eventSource = new EventSource(eventSourceUrl);
|
|
46
48
|
let wasConnectedOnce = false;
|
|
47
49
|
let isConnected = false;
|
|
48
50
|
|
|
@@ -134,7 +136,8 @@ async function handleConnectEvent(
|
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
// Subscribe to the PocketBase realtime API
|
|
137
|
-
const
|
|
139
|
+
const eventSourceUrl = new URL("api/realtime/subscribe", options.url).href;
|
|
140
|
+
const result = await fetch(eventSourceUrl, {
|
|
138
141
|
method: "POST",
|
|
139
142
|
headers: {
|
|
140
143
|
"Content-Type": "application/json",
|
|
@@ -18,6 +18,7 @@ export function handleRefreshCollections({
|
|
|
18
18
|
// Listen for the refresh event of the toolbar
|
|
19
19
|
toolbar.on(
|
|
20
20
|
"astro-integration-pocketbase:refresh",
|
|
21
|
+
// oxlint-disable-next-line strict-void-return
|
|
21
22
|
async ({ force }: { force: boolean }) => {
|
|
22
23
|
// Send a loading state to the toolbar
|
|
23
24
|
toolbar.send("astro-integration-pocketbase:refresh", {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
1
2
|
import type { AstroIntegration } from "astro";
|
|
2
3
|
import type { EventSource } from "eventsource";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { handleRefreshCollections, refreshCollectionsRealtime } from "./core";
|
|
5
5
|
import type { ToolbarOptions } from "./toolbar/types/options";
|
|
6
6
|
import type { PocketBaseIntegrationOptions } from "./types/pocketbase-integration-options.type";
|
|
@@ -35,8 +35,9 @@ function createEntity(data: Entity, baseUrl: string): string {
|
|
|
35
35
|
<div class="entity">
|
|
36
36
|
<pre>${JSON.stringify(data, undefined, 2).replaceAll("<", "<")}</pre>
|
|
37
37
|
|
|
38
|
-
${
|
|
39
|
-
|
|
38
|
+
${
|
|
39
|
+
baseUrl
|
|
40
|
+
? /* HTML */ `
|
|
40
41
|
<astro-dev-toolbar-button
|
|
41
42
|
size="small"
|
|
42
43
|
button-style="purple"
|
|
@@ -46,7 +47,8 @@ function createEntity(data: Entity, baseUrl: string): string {
|
|
|
46
47
|
View in PocketBase
|
|
47
48
|
</astro-dev-toolbar-button>
|
|
48
49
|
`
|
|
49
|
-
|
|
50
|
+
: ""
|
|
51
|
+
}
|
|
50
52
|
</div>
|
|
51
53
|
</astro-dev-toolbar-card>
|
|
52
54
|
`;
|
|
@@ -59,8 +59,9 @@ export function createHeader(
|
|
|
59
59
|
</astro-dev-toolbar-badge>
|
|
60
60
|
|
|
61
61
|
<div class="actions">
|
|
62
|
-
${
|
|
63
|
-
|
|
62
|
+
${
|
|
63
|
+
realtime
|
|
64
|
+
? /* HTML */ `
|
|
64
65
|
<div class="toggle-container">
|
|
65
66
|
<label
|
|
66
67
|
for="real-time"
|
|
@@ -71,9 +72,11 @@ export function createHeader(
|
|
|
71
72
|
<!-- real-time-toggle -->
|
|
72
73
|
</div>
|
|
73
74
|
`
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
: ""
|
|
76
|
+
}
|
|
77
|
+
${
|
|
78
|
+
hasContentLoader
|
|
79
|
+
? /* HTML */ `
|
|
77
80
|
<astro-dev-toolbar-button
|
|
78
81
|
id="refresh-content"
|
|
79
82
|
size="small"
|
|
@@ -83,7 +86,8 @@ export function createHeader(
|
|
|
83
86
|
Refresh content
|
|
84
87
|
</astro-dev-toolbar-button>
|
|
85
88
|
`
|
|
86
|
-
|
|
89
|
+
: ""
|
|
90
|
+
}
|
|
87
91
|
</div>
|
|
88
92
|
`;
|
|
89
93
|
|
|
@@ -75,9 +75,11 @@ export function initToolbar(
|
|
|
75
75
|
<hr />
|
|
76
76
|
|
|
77
77
|
<main>
|
|
78
|
-
${
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
${
|
|
79
|
+
entities.length > 0
|
|
80
|
+
? createEntities(entities, options.baseUrl)
|
|
81
|
+
: createPlaceholder()
|
|
82
|
+
}
|
|
81
83
|
</main>
|
|
82
84
|
`);
|
|
83
85
|
|
|
@@ -47,7 +47,9 @@ export async function getSuperuserToken(
|
|
|
47
47
|
// Random wait between 3 (default rate limit interval) and 8 seconds
|
|
48
48
|
const retryAfter = Math.random() * 5 + 3;
|
|
49
49
|
// oxlint-disable-next-line promise/avoid-new
|
|
50
|
-
await new Promise((resolve) =>
|
|
50
|
+
await new Promise((resolve) => {
|
|
51
|
+
setTimeout(resolve, retryAfter * 1000);
|
|
52
|
+
});
|
|
51
53
|
|
|
52
54
|
return getSuperuserToken(url, superuserCredentials, logger);
|
|
53
55
|
}
|
|
@@ -11,14 +11,14 @@ export function mapCollectionsToWatch(
|
|
|
11
11
|
): Map<string, Array<string>> | undefined {
|
|
12
12
|
// Check if collections should be watched
|
|
13
13
|
if (!collectionsToWatch) {
|
|
14
|
-
return;
|
|
14
|
+
return undefined;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// Check if collectionsToWatch is an array
|
|
18
18
|
if (Array.isArray(collectionsToWatch)) {
|
|
19
19
|
// Check if the array is empty
|
|
20
20
|
if (collectionsToWatch.length === 0) {
|
|
21
|
-
return;
|
|
21
|
+
return undefined;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// Create a map where each collection is watched by itself
|
|
@@ -29,7 +29,7 @@ export function mapCollectionsToWatch(
|
|
|
29
29
|
|
|
30
30
|
// Check if collectionsToWatch is an empty object
|
|
31
31
|
if (Object.keys(collectionsToWatch).length === 0) {
|
|
32
|
-
return;
|
|
32
|
+
return undefined;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Map collections to watch
|