@lumibase/astro 0.0.0-stage → 2.2.2
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/LICENSE +192 -0
- package/README.md +22 -2
- package/dist/chunk-PLXVBHVX.js +39 -0
- package/dist/client.d.ts +27 -0
- package/dist/client.js +27 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +93 -0
- package/dist/loader.d.ts +63 -0
- package/dist/loader.js +6 -0
- package/package.json +66 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
Copyright 2024-present LumiBase Contributors
|
|
181
|
+
|
|
182
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
183
|
+
you may not use this file except in compliance with the License.
|
|
184
|
+
You may obtain a copy of the License at
|
|
185
|
+
|
|
186
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
187
|
+
|
|
188
|
+
Unless required by applicable law or agreed to in writing, software
|
|
189
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
190
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
191
|
+
See the License for the specific language governing permissions and
|
|
192
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@lumibase/astro`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Astro 5–7 integration, Content Layer loader and client realtime helper for [LumiBase](https://lumibase.dev). A thin, typed layer over [`@lumibase/sdk`](../sdk).
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add @lumibase/astro @lumibase/sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
// astro.config.mjs
|
|
11
|
+
import lumibase from '@lumibase/astro';
|
|
12
|
+
export default defineConfig({ integrations: [lumibase({ url, siteId })] });
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// any .astro frontmatter: server-only, token read from LUMIBASE_TOKEN at runtime
|
|
17
|
+
import { lumi } from 'virtual:lumibase';
|
|
18
|
+
|
|
19
|
+
// src/content.config.ts
|
|
20
|
+
import { lumibaseLoader } from '@lumibase/astro/loader';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Full guide: [docs/en/sdk/frameworks.md](../../docs/en/sdk/frameworks.md).
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/loader.ts
|
|
2
|
+
import {
|
|
3
|
+
createLumiClient,
|
|
4
|
+
readItems
|
|
5
|
+
} from "@lumibase/sdk";
|
|
6
|
+
function isClient(value) {
|
|
7
|
+
return typeof value.request === "function";
|
|
8
|
+
}
|
|
9
|
+
function lumibaseLoader(options) {
|
|
10
|
+
const pageSize = options.pageSize ?? 100;
|
|
11
|
+
if (!Number.isInteger(pageSize) || pageSize < 1) throw new Error("[@lumibase/astro] pageSize must be a positive integer");
|
|
12
|
+
return {
|
|
13
|
+
name: "lumibase-loader",
|
|
14
|
+
...options.schema !== void 0 ? { schema: options.schema } : {},
|
|
15
|
+
async load({ store, logger, parseData, generateDigest }) {
|
|
16
|
+
const client = isClient(options.client) ? options.client : createLumiClient(options.client);
|
|
17
|
+
const rows = [];
|
|
18
|
+
for (let offset = 0; ; offset += pageSize) {
|
|
19
|
+
const page = await client.request(
|
|
20
|
+
readItems(options.collection, { ...options.params, limit: pageSize, offset, meta: "none" })
|
|
21
|
+
);
|
|
22
|
+
const batch = page.data;
|
|
23
|
+
rows.push(...batch);
|
|
24
|
+
if (batch.length < pageSize) break;
|
|
25
|
+
}
|
|
26
|
+
store.clear();
|
|
27
|
+
for (const row of rows) {
|
|
28
|
+
const raw = row;
|
|
29
|
+
const data = await parseData({ id: row.id, data: raw });
|
|
30
|
+
store.set({ id: row.id, data, digest: generateDigest(raw) });
|
|
31
|
+
}
|
|
32
|
+
logger.info(`Loaded ${rows.length} ${options.collection} item(s) from LumiBase`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
lumibaseLoader
|
|
39
|
+
};
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RealtimeClient, RealtimeEvent } from '@lumibase/sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `@lumibase/astro/client` — realtime helper for client `<script>`s.
|
|
5
|
+
*
|
|
6
|
+
* ```astro
|
|
7
|
+
* <script>
|
|
8
|
+
* import { RealtimeClient } from '@lumibase/sdk';
|
|
9
|
+
* import { watchCollection } from '@lumibase/astro/client';
|
|
10
|
+
* const rt = new RealtimeClient({ baseUrl, siteId, token: publicToken });
|
|
11
|
+
* watchCollection(rt, 'posts', () => location.reload());
|
|
12
|
+
* </script>
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* The subscription is removed — and the shared connection released — on the
|
|
16
|
+
* returned stop, on `pagehide`, and on Astro's `astro:before-swap` (view
|
|
17
|
+
* transitions keep the document, so without it subscriptions would pile up
|
|
18
|
+
* across navigations). Inside framework islands use `@lumibase/vue` or
|
|
19
|
+
* `@lumibase/svelte` instead; they tie cleanup to the component.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
declare const CLEANUP_EVENTS: readonly ["astro:before-swap", "pagehide"];
|
|
23
|
+
declare function watchCollection(realtime: RealtimeClient, collection: string, handler: (event: RealtimeEvent) => void, options?: {
|
|
24
|
+
filter?: Record<string, unknown>;
|
|
25
|
+
}): () => void;
|
|
26
|
+
|
|
27
|
+
export { CLEANUP_EVENTS, watchCollection };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import { retainRealtime } from "@lumibase/sdk";
|
|
3
|
+
var CLEANUP_EVENTS = ["astro:before-swap", "pagehide"];
|
|
4
|
+
function watchCollection(realtime, collection, handler, options = {}) {
|
|
5
|
+
if (typeof window === "undefined" || typeof document === "undefined") return () => {
|
|
6
|
+
};
|
|
7
|
+
const release = retainRealtime(realtime);
|
|
8
|
+
const off = realtime.subscribe(collection, handler, { filter: options.filter });
|
|
9
|
+
let stopped = false;
|
|
10
|
+
const stop = () => {
|
|
11
|
+
if (stopped) return;
|
|
12
|
+
stopped = true;
|
|
13
|
+
for (const name of CLEANUP_EVENTS) {
|
|
14
|
+
document.removeEventListener(name, stop);
|
|
15
|
+
window.removeEventListener(name, stop);
|
|
16
|
+
}
|
|
17
|
+
off();
|
|
18
|
+
release();
|
|
19
|
+
};
|
|
20
|
+
document.addEventListener("astro:before-swap", stop);
|
|
21
|
+
window.addEventListener("pagehide", stop);
|
|
22
|
+
return stop;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
CLEANUP_EVENTS,
|
|
26
|
+
watchCollection
|
|
27
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export { LoaderContextLike, LumibaseLoader, LumibaseLoaderOptions, lumibaseLoader } from './loader.js';
|
|
2
|
+
import '@lumibase/sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@lumibase/astro` — Astro integration.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // astro.config.mjs
|
|
9
|
+
* import lumibase from '@lumibase/astro';
|
|
10
|
+
* export default defineConfig({
|
|
11
|
+
* integrations: [lumibase({ url: 'https://cms.example.com', siteId: 'site_123' })],
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* // src/pages/index.astro (frontmatter)
|
|
15
|
+
* import { lumi } from 'virtual:lumibase';
|
|
16
|
+
* import { readItems } from '@lumibase/sdk';
|
|
17
|
+
* const posts = await lumi.request(readItems('posts', { limit: 10 }));
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The integration adds one server-only virtual module, `virtual:lumibase`,
|
|
21
|
+
* exporting a configured SDK client. The token is never an integration
|
|
22
|
+
* option: the module reads `<tokenEnv>` (default `LUMIBASE_TOKEN`) with
|
|
23
|
+
* `getSecret()` from `astro:env/server` when the server runs (never inlined at
|
|
24
|
+
* build time), and importing it from browser code fails
|
|
25
|
+
* the build instead of shipping the token.
|
|
26
|
+
*
|
|
27
|
+
* Typed structurally against Astro's integration API (5.x–7.x), so this
|
|
28
|
+
* package does not depend on `astro`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
declare const VIRTUAL_MODULE_ID = "virtual:lumibase";
|
|
32
|
+
interface LumibaseIntegrationOptions {
|
|
33
|
+
/** CMS base URL. */
|
|
34
|
+
url: string;
|
|
35
|
+
/** Site (tenant) id. */
|
|
36
|
+
siteId: string;
|
|
37
|
+
/** Env var holding the server token. Default `LUMIBASE_TOKEN`. */
|
|
38
|
+
tokenEnv?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Extension point: module specifiers imported on every page via
|
|
41
|
+
* `injectScript('page', …)`. This is where a future visual-editing client
|
|
42
|
+
* (V03, `@lumibase/visual-editing`, #681) would hook in; the adapter ships
|
|
43
|
+
* none itself.
|
|
44
|
+
*/
|
|
45
|
+
pageScripts?: string[];
|
|
46
|
+
}
|
|
47
|
+
/** The parts of Astro's `astro:config:setup` / `astro:config:done` params used here. */
|
|
48
|
+
interface AstroConfigSetupLike {
|
|
49
|
+
updateConfig(config: {
|
|
50
|
+
vite?: {
|
|
51
|
+
plugins?: unknown[];
|
|
52
|
+
};
|
|
53
|
+
}): unknown;
|
|
54
|
+
injectScript(stage: "head-inline" | "before-hydration" | "page" | "page-ssr", content: string): void;
|
|
55
|
+
}
|
|
56
|
+
interface AstroConfigDoneLike {
|
|
57
|
+
/** Astro ≥ 5. */
|
|
58
|
+
injectTypes?(input: {
|
|
59
|
+
filename: string;
|
|
60
|
+
content: string;
|
|
61
|
+
}): unknown;
|
|
62
|
+
}
|
|
63
|
+
interface LumibaseIntegration {
|
|
64
|
+
name: string;
|
|
65
|
+
hooks: {
|
|
66
|
+
"astro:config:setup": (params: AstroConfigSetupLike) => void;
|
|
67
|
+
"astro:config:done": (params: AstroConfigDoneLike) => void;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Minimal Vite plugin shape (structural; no `vite` import). */
|
|
71
|
+
interface VirtualModulePlugin {
|
|
72
|
+
name: string;
|
|
73
|
+
enforce: "pre";
|
|
74
|
+
resolveId(id: string): string | undefined;
|
|
75
|
+
load(this: {
|
|
76
|
+
environment?: {
|
|
77
|
+
config?: {
|
|
78
|
+
consumer?: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
} | void, id: string, options?: {
|
|
82
|
+
ssr?: boolean;
|
|
83
|
+
}): string | undefined;
|
|
84
|
+
}
|
|
85
|
+
/** Source of `virtual:lumibase`. Contains the env var *name*, never a token. */
|
|
86
|
+
declare function virtualModuleSource(options: LumibaseIntegrationOptions): string;
|
|
87
|
+
declare const VIRTUAL_MODULE_TYPES = "declare module \"virtual:lumibase\" {\n import type { LumiClient } from \"@lumibase/sdk\";\n export const config: { url: string; siteId: string };\n export function createClient(token?: string): LumiClient;\n export const lumi: LumiClient;\n}\n";
|
|
88
|
+
/** Vite plugin serving `virtual:lumibase`; refuses to load it into a client bundle. */
|
|
89
|
+
declare function lumibaseVitePlugin(options: LumibaseIntegrationOptions): VirtualModulePlugin;
|
|
90
|
+
/** The Astro integration. */
|
|
91
|
+
declare function lumibase(options: LumibaseIntegrationOptions): LumibaseIntegration;
|
|
92
|
+
|
|
93
|
+
export { VIRTUAL_MODULE_ID, VIRTUAL_MODULE_TYPES, lumibase as default, lumibaseVitePlugin, virtualModuleSource };
|
|
94
|
+
export type { AstroConfigDoneLike, AstroConfigSetupLike, LumibaseIntegration, LumibaseIntegrationOptions, VirtualModulePlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lumibaseLoader
|
|
3
|
+
} from "./chunk-PLXVBHVX.js";
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
var VIRTUAL_MODULE_ID = "virtual:lumibase";
|
|
7
|
+
var RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
8
|
+
var ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
9
|
+
function validate(options) {
|
|
10
|
+
const tokenEnv = options.tokenEnv ?? "LUMIBASE_TOKEN";
|
|
11
|
+
if (!ENV_NAME.test(tokenEnv)) throw new Error(`[@lumibase/astro] tokenEnv must be an identifier, got ${JSON.stringify(tokenEnv)}`);
|
|
12
|
+
if (!options.url || !options.siteId) throw new Error("[@lumibase/astro] `url` and `siteId` are required.");
|
|
13
|
+
return { url: options.url, siteId: options.siteId, tokenEnv };
|
|
14
|
+
}
|
|
15
|
+
var UNSAFE_IN_CODE = {
|
|
16
|
+
"<": "\\u003C",
|
|
17
|
+
">": "\\u003E",
|
|
18
|
+
"\u2028": "\\u2028",
|
|
19
|
+
"\u2029": "\\u2029"
|
|
20
|
+
};
|
|
21
|
+
function codeLiteral(value) {
|
|
22
|
+
return JSON.stringify(value).replace(/[<>\u2028\u2029]/g, (ch) => UNSAFE_IN_CODE[ch] ?? ch);
|
|
23
|
+
}
|
|
24
|
+
function virtualModuleSource(options) {
|
|
25
|
+
const { url, siteId, tokenEnv } = validate(options);
|
|
26
|
+
return [
|
|
27
|
+
`import { createLumiClient } from "@lumibase/sdk";`,
|
|
28
|
+
// `getSecret` reads the variable when the server runs, through the
|
|
29
|
+
// adapter (Node `process.env`, Cloudflare bindings, …). `import.meta.env.X`
|
|
30
|
+
// would be replaced by Vite at build time, baking the build machine's token
|
|
31
|
+
// into `dist/server` of an SSR build.
|
|
32
|
+
`import { getSecret } from "astro:env/server";`,
|
|
33
|
+
`export const config = { url: ${codeLiteral(url)}, siteId: ${codeLiteral(siteId)} };`,
|
|
34
|
+
`export function createClient(token = getSecret(${codeLiteral(tokenEnv)}) ?? "") {`,
|
|
35
|
+
` return createLumiClient({ ...config, token });`,
|
|
36
|
+
`}`,
|
|
37
|
+
`export const lumi = createClient();`,
|
|
38
|
+
``
|
|
39
|
+
].join("\n");
|
|
40
|
+
}
|
|
41
|
+
var VIRTUAL_MODULE_TYPES = `declare module "${VIRTUAL_MODULE_ID}" {
|
|
42
|
+
import type { LumiClient } from "@lumibase/sdk";
|
|
43
|
+
export const config: { url: string; siteId: string };
|
|
44
|
+
export function createClient(token?: string): LumiClient;
|
|
45
|
+
export const lumi: LumiClient;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
function lumibaseVitePlugin(options) {
|
|
49
|
+
const source = virtualModuleSource(options);
|
|
50
|
+
return {
|
|
51
|
+
name: "lumibase:virtual-module",
|
|
52
|
+
enforce: "pre",
|
|
53
|
+
resolveId(id) {
|
|
54
|
+
return id === VIRTUAL_MODULE_ID ? RESOLVED_VIRTUAL_MODULE_ID : void 0;
|
|
55
|
+
},
|
|
56
|
+
load(id, loadOptions) {
|
|
57
|
+
if (id !== RESOLVED_VIRTUAL_MODULE_ID) return void 0;
|
|
58
|
+
const consumer = this && this.environment?.config?.consumer;
|
|
59
|
+
const onServer = consumer ? consumer === "server" : loadOptions?.ssr === true;
|
|
60
|
+
if (!onServer) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`[@lumibase/astro] "${VIRTUAL_MODULE_ID}" is server-only (it reads your LumiBase token). Import it from frontmatter, endpoints or middleware \u2014 not from a client <script> or island.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return source;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function lumibase(options) {
|
|
70
|
+
validate(options);
|
|
71
|
+
return {
|
|
72
|
+
name: "@lumibase/astro",
|
|
73
|
+
hooks: {
|
|
74
|
+
"astro:config:setup": ({ updateConfig, injectScript }) => {
|
|
75
|
+
updateConfig({ vite: { plugins: [lumibaseVitePlugin(options)] } });
|
|
76
|
+
for (const spec of options.pageScripts ?? []) {
|
|
77
|
+
injectScript("page", `import ${JSON.stringify(spec)};`);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"astro:config:done": ({ injectTypes }) => {
|
|
81
|
+
injectTypes?.({ filename: "lumibase.d.ts", content: VIRTUAL_MODULE_TYPES });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
VIRTUAL_MODULE_ID,
|
|
88
|
+
VIRTUAL_MODULE_TYPES,
|
|
89
|
+
lumibase as default,
|
|
90
|
+
lumibaseLoader,
|
|
91
|
+
lumibaseVitePlugin,
|
|
92
|
+
virtualModuleSource
|
|
93
|
+
};
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { DefaultSchema, LumiClient, LumiClientOptions, ListItemsParams } from '@lumibase/sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `@lumibase/astro/loader` — Astro Content Layer loader (Astro ≥ 5).
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* // src/content.config.ts
|
|
8
|
+
* import { defineCollection } from 'astro:content';
|
|
9
|
+
* import { lumibaseLoader } from '@lumibase/astro/loader';
|
|
10
|
+
* export const collections = {
|
|
11
|
+
* posts: defineCollection({
|
|
12
|
+
* loader: lumibaseLoader({
|
|
13
|
+
* client: { url: 'https://cms.example.com', siteId: 'site_123', token: import.meta.env.LUMIBASE_TOKEN },
|
|
14
|
+
* collection: 'posts',
|
|
15
|
+
* params: { status: 'published' },
|
|
16
|
+
* }),
|
|
17
|
+
* }),
|
|
18
|
+
* };
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Each entry is the full item row (`id`, `status`, `data`, …) keyed by its
|
|
22
|
+
* id; pages are fetched with the SDK's `readItems` until a short page.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** The part of Astro's `LoaderContext` this loader uses. */
|
|
26
|
+
interface LoaderContextLike {
|
|
27
|
+
store: {
|
|
28
|
+
clear(): void;
|
|
29
|
+
set(entry: {
|
|
30
|
+
id: string;
|
|
31
|
+
data: Record<string, unknown>;
|
|
32
|
+
digest?: string | number;
|
|
33
|
+
}): boolean;
|
|
34
|
+
};
|
|
35
|
+
logger: {
|
|
36
|
+
info(message: string): void;
|
|
37
|
+
};
|
|
38
|
+
parseData<T extends Record<string, unknown>>(props: {
|
|
39
|
+
id: string;
|
|
40
|
+
data: T;
|
|
41
|
+
}): Promise<T>;
|
|
42
|
+
generateDigest(data: Record<string, unknown> | string): string;
|
|
43
|
+
}
|
|
44
|
+
interface LumibaseLoaderOptions<TSchema extends DefaultSchema, C extends keyof TSchema & string> {
|
|
45
|
+
/** An SDK client, or the options to build one (build/sync time only — never shipped). */
|
|
46
|
+
client: LumiClient<TSchema> | Pick<LumiClientOptions, "url" | "siteId" | "token" | "fetcher">;
|
|
47
|
+
collection: C;
|
|
48
|
+
/** Filters/sort/fields; `limit`/`offset` are driven by the loader. */
|
|
49
|
+
params?: Omit<ListItemsParams, "limit" | "offset" | "meta">;
|
|
50
|
+
/** Rows per request. Default 100. */
|
|
51
|
+
pageSize?: number;
|
|
52
|
+
/** Optional Astro schema (e.g. a zod object) validated by `parseData`. */
|
|
53
|
+
schema?: unknown;
|
|
54
|
+
}
|
|
55
|
+
interface LumibaseLoader {
|
|
56
|
+
name: string;
|
|
57
|
+
schema?: unknown;
|
|
58
|
+
load(context: LoaderContextLike): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
declare function lumibaseLoader<TSchema extends DefaultSchema = DefaultSchema, C extends keyof TSchema & string = keyof TSchema & string>(options: LumibaseLoaderOptions<TSchema, C>): LumibaseLoader;
|
|
61
|
+
|
|
62
|
+
export { lumibaseLoader };
|
|
63
|
+
export type { LoaderContextLike, LumibaseLoader, LumibaseLoaderOptions };
|
package/dist/loader.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumibase/astro",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.2.2",
|
|
4
|
+
"description": "Astro integration, content-layer loader and client realtime helper for LumiBase — a thin, typed layer over @lumibase/sdk.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/khuepm/lumibase.git",
|
|
10
|
+
"directory": "packages/astro"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://docs.lumibase.dev",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/khuepm/lumibase/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"lumibase",
|
|
18
|
+
"cms",
|
|
19
|
+
"headless-cms",
|
|
20
|
+
"astro",
|
|
21
|
+
"astro-integration",
|
|
22
|
+
"astro-loader",
|
|
23
|
+
"withastro"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./loader": {
|
|
33
|
+
"types": "./dist/loader.d.ts",
|
|
34
|
+
"import": "./dist/loader.js"
|
|
35
|
+
},
|
|
36
|
+
"./client": {
|
|
37
|
+
"types": "./dist/client.d.ts",
|
|
38
|
+
"import": "./dist/client.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@lumibase/sdk": "2.2.2"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"astro": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"jsdom": "^31.0.1",
|
|
55
|
+
"tsup": "^9.0.0",
|
|
56
|
+
"typescript": "^5.6.2",
|
|
57
|
+
"vitest": "^5.1.1"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"dist"
|
|
61
|
+
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"typecheck": "tsc --noEmit",
|
|
66
|
+
"clean": "rm -rf .turbo dist"
|
|
67
|
+
},
|
|
68
|
+
"module": "./dist/index.js"
|
|
6
69
|
}
|