@maravilla-labs/adapter-astro 0.2.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.
- package/LICENSE +12 -0
- package/README.md +92 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +184 -0
- package/dist/index.js.map +1 -0
- package/dist/server-entrypoint.d.ts +12 -0
- package/dist/server-entrypoint.d.ts.map +1 -0
- package/dist/server-entrypoint.js +37 -0
- package/dist/server-entrypoint.js.map +1 -0
- package/dist/session-driver.d.ts +27 -0
- package/dist/session-driver.d.ts.map +1 -0
- package/dist/session-driver.js +65 -0
- package/dist/session-driver.js.map +1 -0
- package/dist/shims/buffer.d.ts +23 -0
- package/dist/shims/buffer.d.ts.map +1 -0
- package/dist/shims/buffer.js +96 -0
- package/dist/shims/buffer.js.map +1 -0
- package/dist/shims/crypto.d.ts +31 -0
- package/dist/shims/crypto.d.ts.map +1 -0
- package/dist/shims/crypto.js +54 -0
- package/dist/shims/crypto.js.map +1 -0
- package/dist/shims/fs-promises.d.ts +7 -0
- package/dist/shims/fs-promises.d.ts.map +1 -0
- package/dist/shims/fs-promises.js +7 -0
- package/dist/shims/fs-promises.js.map +1 -0
- package/dist/shims/fs.d.ts +37 -0
- package/dist/shims/fs.d.ts.map +1 -0
- package/dist/shims/fs.js +48 -0
- package/dist/shims/fs.js.map +1 -0
- package/dist/shims/module.d.ts +9 -0
- package/dist/shims/module.d.ts.map +1 -0
- package/dist/shims/module.js +10 -0
- package/dist/shims/module.js.map +1 -0
- package/dist/shims/os.d.ts +17 -0
- package/dist/shims/os.d.ts.map +1 -0
- package/dist/shims/os.js +18 -0
- package/dist/shims/os.js.map +1 -0
- package/dist/shims/path.d.ts +65 -0
- package/dist/shims/path.d.ts.map +1 -0
- package/dist/shims/path.js +99 -0
- package/dist/shims/path.js.map +1 -0
- package/dist/shims/process.d.ts +15 -0
- package/dist/shims/process.d.ts.map +1 -0
- package/dist/shims/process.js +29 -0
- package/dist/shims/process.js.map +1 -0
- package/dist/shims/url.d.ts +37 -0
- package/dist/shims/url.d.ts.map +1 -0
- package/dist/shims/url.js +30 -0
- package/dist/shims/url.js.map +1 -0
- package/dist/worker-template.d.ts +14 -0
- package/dist/worker-template.d.ts.map +1 -0
- package/dist/worker-template.js +37 -0
- package/dist/worker-template.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SOLUTAS GmbH, Switzerland. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software and associated documentation (the "Software") are the confidential and proprietary information of SOLUTAS GmbH ("SOLUTAS"). By using, copying, or accessing the Software, you agree that:
|
|
6
|
+
|
|
7
|
+
- No rights are granted except as expressly set forth in a separate written agreement with SOLUTAS.
|
|
8
|
+
- You may not copy, modify, distribute, sublicense, reverse engineer, or create derivative works of the Software except as permitted in such agreement.
|
|
9
|
+
- The Software is provided "as is" without warranty of any kind; SOLUTAS disclaims all implied warranties to the maximum extent permitted by law.
|
|
10
|
+
- In no event shall SOLUTAS be liable for any damages arising from use of the Software except as expressly provided in an applicable agreement.
|
|
11
|
+
|
|
12
|
+
For licensing inquiries, contact: legal@solutas.ch
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @maravilla-labs/adapter-astro
|
|
2
|
+
|
|
3
|
+
Astro adapter for Maravilla Runtime. Builds an Astro app (server, hybrid, or
|
|
4
|
+
static output) into a Maravilla bundle: `manifest.json` + `server.js` +
|
|
5
|
+
`static/`.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
// astro.config.mjs
|
|
11
|
+
import { defineConfig } from 'astro/config';
|
|
12
|
+
import maravilla from '@maravilla-labs/adapter-astro';
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
output: 'server', // or 'static' with per-page `export const prerender = false`
|
|
16
|
+
adapter: maravilla(),
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
astro build # writes .maravilla/
|
|
24
|
+
maravilla preview .maravilla
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Platform services
|
|
28
|
+
|
|
29
|
+
Platform bindings are exposed on `locals` (Astro's idiomatic per-request
|
|
30
|
+
context):
|
|
31
|
+
|
|
32
|
+
```astro
|
|
33
|
+
---
|
|
34
|
+
const { platform } = Astro.locals;
|
|
35
|
+
const value = await platform.env.KV.demo.get('key');
|
|
36
|
+
const docs = await platform.env.DB.find('notes', {});
|
|
37
|
+
---
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
API routes receive the same `locals`:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
export const GET: APIRoute = async ({ locals }) => {
|
|
44
|
+
const notes = await locals.platform.env.DB.find('notes', {});
|
|
45
|
+
return Response.json({ notes });
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Add the locals typing to `src/env.d.ts` (see `examples/demo/src/env.d.ts`).
|
|
50
|
+
|
|
51
|
+
## Sessions
|
|
52
|
+
|
|
53
|
+
`Astro.session` works out of the box: the adapter wires a KV-backed session
|
|
54
|
+
driver (namespace `astro_sessions`) as the default `session.driver`. During
|
|
55
|
+
`astro dev` (plain Node, no platform bindings) the driver falls back to an
|
|
56
|
+
in-memory store. Configure with adapter options:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
maravilla({ sessionNamespace: 'my_sessions' }) // custom KV namespace
|
|
60
|
+
maravilla({ sessionDriver: false }) // opt out of the default driver
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
A user-configured `session.driver` in the Astro config always wins.
|
|
64
|
+
|
|
65
|
+
## Images
|
|
66
|
+
|
|
67
|
+
Sharp cannot run in the isolate; the adapter configures Astro's passthrough
|
|
68
|
+
image service automatically (images are served unoptimized). A custom image
|
|
69
|
+
endpoint backed by the Maravilla media pipeline is a planned follow-up.
|
|
70
|
+
|
|
71
|
+
## Options
|
|
72
|
+
|
|
73
|
+
Standard adapter options shared with the other Maravilla adapters:
|
|
74
|
+
`out` (default `.maravilla`), `envPrefix` (default `PUBLIC_`), `include`,
|
|
75
|
+
`exclude`, `external`, `polyfill`, `precompress` — plus the session options
|
|
76
|
+
above.
|
|
77
|
+
|
|
78
|
+
Edge functions (`functions/`), event handlers (`events.ts`), workflows and
|
|
79
|
+
MCP tools are picked up from the project root exactly as with the SvelteKit
|
|
80
|
+
adapter.
|
|
81
|
+
|
|
82
|
+
## Requirements
|
|
83
|
+
|
|
84
|
+
- Astro 6 or 7 ('auto' entrypoint resolution).
|
|
85
|
+
- The adapter forces a server build (`buildOutput: 'server'`); fully
|
|
86
|
+
prerendered pages are listed in the manifest's `routing.prerendered` and
|
|
87
|
+
served statically without touching the isolate.
|
|
88
|
+
|
|
89
|
+
## Example
|
|
90
|
+
|
|
91
|
+
See `examples/demo` for an app exercising SSR, a prerendered page, platform
|
|
92
|
+
KV/DB and sessions.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro';
|
|
2
|
+
import { type AdapterOptions } from '@maravilla-labs/adapter-core';
|
|
3
|
+
export type { MaravillaLocals } from './server-entrypoint.js';
|
|
4
|
+
export type { MaravillaSessionDriverConfig } from './session-driver.js';
|
|
5
|
+
export { WORKER_TEMPLATE } from './worker-template.js';
|
|
6
|
+
export interface AstroAdapterOptions extends AdapterOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Auto-wire the KV-backed session driver as the default `session.driver`
|
|
9
|
+
* so `Astro.session` works out of the box (default: true). A driver the
|
|
10
|
+
* user configured explicitly always wins.
|
|
11
|
+
*/
|
|
12
|
+
sessionDriver?: boolean;
|
|
13
|
+
/** KV namespace used by the default session driver (default: 'astro_sessions') */
|
|
14
|
+
sessionNamespace?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Astro adapter (integration) for Maravilla Runtime.
|
|
18
|
+
*
|
|
19
|
+
* Registers a web-standard server entrypoint (`app.render(Request) ->
|
|
20
|
+
* Response` via Astro's 'auto' entrypoint resolution) and, after Astro's
|
|
21
|
+
* build, produces a Maravilla bundle in `.maravilla/`:
|
|
22
|
+
* `manifest.json` + `server.js` + `static/` (client assets and prerendered
|
|
23
|
+
* HTML), following the same contract as the SvelteKit and React Router
|
|
24
|
+
* adapters.
|
|
25
|
+
*/
|
|
26
|
+
export default function maravilla(options?: AstroAdapterOptions): AstroIntegration;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,EAWL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAItC,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kFAAkF;IAClF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAsBD;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,GAAE,mBAAwB,GAAG,gBAAgB,CAyLrF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { writeFileSync, mkdirSync, cpSync, existsSync, rmSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { passthroughImageService } from 'astro/config';
|
|
5
|
+
import { bundleServerEntry, analyzeBundle, generateManifest, writeManifest, collectAssets, buildAndIntegrateFunctions, buildAndIntegrateEvents, buildAndIntegrateWorkflows, buildAndIntegrateMcp, loadMaravillaConfig, } from '@maravilla-labs/adapter-core';
|
|
6
|
+
import { WORKER_TEMPLATE } from './worker-template.js';
|
|
7
|
+
export { WORKER_TEMPLATE } from './worker-template.js';
|
|
8
|
+
/**
|
|
9
|
+
* `node:` builtins that Astro's generated server bundle may import. Each is
|
|
10
|
+
* aliased at esbuild time to a small web-API shim in `./shims/` so the final
|
|
11
|
+
* `server.js` stays web-APIs-only (the runtime's bundle contract).
|
|
12
|
+
*
|
|
13
|
+
* Only the `node:`-prefixed specifiers are aliased: bare `path`, `buffer` etc.
|
|
14
|
+
* are also real npm packages, and rewriting those would silently swap a
|
|
15
|
+
* dependency's userland polyfill for a shim that may not match its API.
|
|
16
|
+
*/
|
|
17
|
+
const NODE_SHIMS = ['buffer', 'crypto', 'path', 'url', 'process', 'os', 'fs', 'fs/promises', 'module'];
|
|
18
|
+
function shimAliases() {
|
|
19
|
+
const aliases = {};
|
|
20
|
+
for (const name of NODE_SHIMS) {
|
|
21
|
+
const file = name.replace('/', '-');
|
|
22
|
+
aliases[`node:${name}`] = fileURLToPath(new URL(`./shims/${file}.js`, import.meta.url));
|
|
23
|
+
}
|
|
24
|
+
return aliases;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Astro adapter (integration) for Maravilla Runtime.
|
|
28
|
+
*
|
|
29
|
+
* Registers a web-standard server entrypoint (`app.render(Request) ->
|
|
30
|
+
* Response` via Astro's 'auto' entrypoint resolution) and, after Astro's
|
|
31
|
+
* build, produces a Maravilla bundle in `.maravilla/`:
|
|
32
|
+
* `manifest.json` + `server.js` + `static/` (client assets and prerendered
|
|
33
|
+
* HTML), following the same contract as the SvelteKit and React Router
|
|
34
|
+
* adapters.
|
|
35
|
+
*/
|
|
36
|
+
export default function maravilla(options = {}) {
|
|
37
|
+
const { out = '.maravilla', precompress = false, envPrefix = 'PUBLIC_', polyfill = true, include = [], exclude = [], external = [], sessionDriver = true, sessionNamespace, } = options;
|
|
38
|
+
let config;
|
|
39
|
+
return {
|
|
40
|
+
name: '@maravilla-labs/adapter-astro',
|
|
41
|
+
hooks: {
|
|
42
|
+
'astro:config:setup': ({ config: userConfig, updateConfig, logger }) => {
|
|
43
|
+
// Sharp cannot run in the isolate: swap the default image service for
|
|
44
|
+
// passthrough. A user-configured non-sharp service is left untouched.
|
|
45
|
+
const serviceEntrypoint = String(userConfig.image?.service?.entrypoint ?? '');
|
|
46
|
+
if (serviceEntrypoint === '' || serviceEntrypoint.includes('sharp')) {
|
|
47
|
+
updateConfig({ image: { service: passthroughImageService() } });
|
|
48
|
+
logger.info('Using passthrough image service (sharp is unsupported in the Maravilla isolate)');
|
|
49
|
+
}
|
|
50
|
+
// Default `Astro.session` to the KV-backed driver unless the user
|
|
51
|
+
// configured their own.
|
|
52
|
+
if (sessionDriver && !userConfig.session?.driver) {
|
|
53
|
+
updateConfig({
|
|
54
|
+
session: {
|
|
55
|
+
driver: {
|
|
56
|
+
entrypoint: '@maravilla-labs/adapter-astro/session-driver',
|
|
57
|
+
...(sessionNamespace ? { config: { namespace: sessionNamespace } } : {}),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
'astro:config:done': ({ config: doneConfig, setAdapter }) => {
|
|
64
|
+
config = doneConfig;
|
|
65
|
+
setAdapter({
|
|
66
|
+
name: '@maravilla-labs/adapter-astro',
|
|
67
|
+
entrypointResolution: 'auto',
|
|
68
|
+
serverEntrypoint: '@maravilla-labs/adapter-astro/server-entrypoint',
|
|
69
|
+
adapterFeatures: {
|
|
70
|
+
// Always emit a server build: the Maravilla manifest contract
|
|
71
|
+
// requires a `server.js` entrypoint even for mostly-static sites;
|
|
72
|
+
// fully prerendered pages are served from static/ without ever
|
|
73
|
+
// touching the isolate.
|
|
74
|
+
buildOutput: 'server',
|
|
75
|
+
middlewareMode: 'classic',
|
|
76
|
+
},
|
|
77
|
+
supportedAstroFeatures: {
|
|
78
|
+
staticOutput: 'stable',
|
|
79
|
+
hybridOutput: 'stable',
|
|
80
|
+
serverOutput: 'stable',
|
|
81
|
+
sharpImageService: {
|
|
82
|
+
support: 'unsupported',
|
|
83
|
+
message: 'Sharp is a native Node module and cannot run in the Maravilla isolate. ' +
|
|
84
|
+
'The adapter configures the passthrough image service automatically.',
|
|
85
|
+
suppress: 'default',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
'astro:build:done': async ({ logger }) => {
|
|
91
|
+
const root = fileURLToPath(config.root);
|
|
92
|
+
const clientDir = fileURLToPath(config.build.client);
|
|
93
|
+
const serverDir = fileURLToPath(config.build.server);
|
|
94
|
+
const serverEntry = join(serverDir, config.build.serverEntry);
|
|
95
|
+
if (!existsSync(serverEntry)) {
|
|
96
|
+
throw new Error(`[maravilla] Astro server entry not found at ${serverEntry}. ` +
|
|
97
|
+
`The adapter requires a server build (it forces buildOutput: 'server').`);
|
|
98
|
+
}
|
|
99
|
+
const outDir = resolve(root, out);
|
|
100
|
+
const tmpDir = resolve(root, 'node_modules/.maravilla-tmp');
|
|
101
|
+
if (existsSync(outDir))
|
|
102
|
+
rmSync(outDir, { recursive: true });
|
|
103
|
+
mkdirSync(outDir, { recursive: true });
|
|
104
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
105
|
+
logger.info('Building Maravilla Runtime bundle...');
|
|
106
|
+
// Copy client assets (including prerendered .html pages) to static/
|
|
107
|
+
const staticDir = join(outDir, 'static');
|
|
108
|
+
if (existsSync(clientDir)) {
|
|
109
|
+
cpSync(clientDir, staticDir, { recursive: true });
|
|
110
|
+
logger.info('Copied client assets to static/');
|
|
111
|
+
}
|
|
112
|
+
// Generate worker entry that imports the Astro server build
|
|
113
|
+
const workerCode = WORKER_TEMPLATE.replace('__SERVER_ENTRY__', serverEntry.replace(/\\/g, '/'));
|
|
114
|
+
const workerPath = join(tmpDir, 'worker.js');
|
|
115
|
+
writeFileSync(workerPath, workerCode);
|
|
116
|
+
// Bundle with esbuild; alias node: builtins to web-API shims so the
|
|
117
|
+
// emitted server.js satisfies the web-APIs-only bundle contract.
|
|
118
|
+
logger.info('Bundling with esbuild...');
|
|
119
|
+
const result = await bundleServerEntry({
|
|
120
|
+
entrypoint: workerPath,
|
|
121
|
+
outfile: join(outDir, 'server.js'),
|
|
122
|
+
external,
|
|
123
|
+
treeShaking: false,
|
|
124
|
+
alias: shimAliases(),
|
|
125
|
+
});
|
|
126
|
+
const analysis = await analyzeBundle(result);
|
|
127
|
+
if (analysis) {
|
|
128
|
+
logger.info(analysis);
|
|
129
|
+
}
|
|
130
|
+
// Collect static assets; prerendered pages are the real on-disk .html
|
|
131
|
+
// files Astro wrote into the client dir (recorded verbatim by
|
|
132
|
+
// generateManifest, per the manifest contract).
|
|
133
|
+
const staticAssets = collectAssets(staticDir);
|
|
134
|
+
const prerenderedPaths = staticAssets.filter((p) => p.endsWith('.html'));
|
|
135
|
+
// Load optional maravilla.config.* with auth/database/studio settings
|
|
136
|
+
const { config: maravillaConfig, path: configPath } = await loadMaravillaConfig(root);
|
|
137
|
+
if (configPath) {
|
|
138
|
+
logger.info(`Loaded maravilla config from ${configPath}`);
|
|
139
|
+
}
|
|
140
|
+
const manifest = generateManifest({
|
|
141
|
+
adapterName: '@maravilla-labs/adapter-astro',
|
|
142
|
+
prerenderedPaths,
|
|
143
|
+
staticAssets,
|
|
144
|
+
include,
|
|
145
|
+
exclude,
|
|
146
|
+
envPrefix,
|
|
147
|
+
features: {
|
|
148
|
+
ssr: true,
|
|
149
|
+
prerendering: prerenderedPaths.length > 0,
|
|
150
|
+
polyfill,
|
|
151
|
+
streaming: true,
|
|
152
|
+
compression: precompress,
|
|
153
|
+
},
|
|
154
|
+
extraMetadata: {
|
|
155
|
+
framework: 'astro',
|
|
156
|
+
},
|
|
157
|
+
auth: maravillaConfig.auth,
|
|
158
|
+
database: maravillaConfig.database,
|
|
159
|
+
studio: maravillaConfig.studio,
|
|
160
|
+
});
|
|
161
|
+
writeManifest(outDir, manifest);
|
|
162
|
+
// Build and integrate edge functions
|
|
163
|
+
await buildAndIntegrateFunctions(root, outDir);
|
|
164
|
+
// Build and integrate event handlers (events.ts / events/**/*.ts).
|
|
165
|
+
// Pass `transforms` so synthesized storage.put handlers from
|
|
166
|
+
// `maravilla.config.ts:transforms` get compiled into events.json.
|
|
167
|
+
await buildAndIntegrateEvents(root, outDir, undefined, {
|
|
168
|
+
transforms: maravillaConfig.transforms,
|
|
169
|
+
});
|
|
170
|
+
// Build and integrate workflows (workflows.ts / workflows/**/*.ts)
|
|
171
|
+
await buildAndIntegrateWorkflows(root, outDir);
|
|
172
|
+
// Build and integrate MCP tools (mcp.ts / mcp/**/*.ts)
|
|
173
|
+
await buildAndIntegrateMcp(root, outDir, undefined, {
|
|
174
|
+
staticDir: 'static',
|
|
175
|
+
});
|
|
176
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
177
|
+
logger.info(`Build complete. Output written to ${out}`);
|
|
178
|
+
logger.info('Preview locally with:');
|
|
179
|
+
logger.info(` maravilla preview ${out}`);
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,uBAAuB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MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBAEjD,MAAM,CAAC,IAAI,CAAC,qCAAqC,GAAG,EAAE,CAAC,CAAC;gBACxD,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;gBACrC,MAAM,CAAC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;YAC5C,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Shape of `Astro.locals` / `context.locals` provided by this adapter. */
|
|
2
|
+
export interface MaravillaLocals {
|
|
3
|
+
/** Full platform bindings object injected by the Maravilla runtime. */
|
|
4
|
+
platform: unknown;
|
|
5
|
+
env: Record<string, unknown>;
|
|
6
|
+
kv: unknown;
|
|
7
|
+
db: unknown;
|
|
8
|
+
storage: unknown;
|
|
9
|
+
queue: unknown;
|
|
10
|
+
}
|
|
11
|
+
export declare function handler(request: Request): Promise<Response>;
|
|
12
|
+
//# sourceMappingURL=server-entrypoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-entrypoint.d.ts","sourceRoot":"","sources":["../src/server-entrypoint.ts"],"names":[],"mappings":"AAgBA,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB;AAcD,wBAAsB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAYjE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Astro server entrypoint for Maravilla Runtime ('auto' entrypoint resolution).
|
|
3
|
+
*
|
|
4
|
+
* Astro's SSR build imports this module and rewrites `astro/app/entrypoint`
|
|
5
|
+
* to the generated, manifest-bound `createApp` (virtual:astro:app). We export
|
|
6
|
+
* a plain web-standard `handler(Request) -> Response`; the adapter's worker
|
|
7
|
+
* template wires it to the runtime's `globalThis.handleRequest` contract.
|
|
8
|
+
*
|
|
9
|
+
* Platform bindings are surfaced to Astro code via `context.locals.platform`
|
|
10
|
+
* (plus flat `locals.env/kv/db/storage/queue` conveniences), mirroring the
|
|
11
|
+
* React Router adapter's loadContext and SvelteKit's `platform` option.
|
|
12
|
+
*/
|
|
13
|
+
import { createApp } from 'astro/app/entrypoint';
|
|
14
|
+
const app = createApp({ streaming: true });
|
|
15
|
+
function buildLocals() {
|
|
16
|
+
const platform = globalThis.platform;
|
|
17
|
+
return {
|
|
18
|
+
platform,
|
|
19
|
+
env: platform?.env ?? {},
|
|
20
|
+
kv: platform?.kv,
|
|
21
|
+
db: platform?.db ?? platform?.database,
|
|
22
|
+
storage: platform?.storage,
|
|
23
|
+
queue: platform?.queue,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export async function handler(request) {
|
|
27
|
+
// Without a client address Astro throws on any `Astro.clientAddress` access,
|
|
28
|
+
// so fall back to loopback when the proxy header is absent (direct
|
|
29
|
+
// `maravilla preview`, for instance).
|
|
30
|
+
const clientAddress = request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() || '127.0.0.1';
|
|
31
|
+
return app.render(request, {
|
|
32
|
+
addCookieHeader: true,
|
|
33
|
+
clientAddress,
|
|
34
|
+
locals: buildLocals(),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=server-entrypoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-entrypoint.js","sourceRoot":"","sources":["../src/server-entrypoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,GAAG,GAAG,SAAS,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAa3C,SAAS,WAAW;IAClB,MAAM,QAAQ,GAAI,UAAkC,CAAC,QAAQ,CAAC;IAC9D,OAAO;QACL,QAAQ;QACR,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE;QACxB,EAAE,EAAE,QAAQ,EAAE,EAAE;QAChB,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,QAAQ,EAAE,QAAQ;QACtC,OAAO,EAAE,QAAQ,EAAE,OAAO;QAC1B,KAAK,EAAE,QAAQ,EAAE,KAAK;KACvB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAgB;IAC5C,6EAA6E;IAC7E,mEAAmE;IACnE,sCAAsC;IACtC,MAAM,aAAa,GACjB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,WAAW,CAAC;IAE/E,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE;QACzB,eAAe,EAAE,IAAI;QACrB,aAAa;QACb,MAAM,EAAE,WAAW,EAAE;KACtB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KV-backed Astro session driver for Maravilla Runtime.
|
|
3
|
+
*
|
|
4
|
+
* Astro sessions are backed by a minimal unstorage-shaped driver
|
|
5
|
+
* (`getItem`/`setItem`/`removeItem` — see astro/dist/core/session/types.d.ts).
|
|
6
|
+
* The adapter wires this module as the default `session.driver` entrypoint so
|
|
7
|
+
* `Astro.session` works out of the box.
|
|
8
|
+
*
|
|
9
|
+
* In production the driver persists to the platform KV store
|
|
10
|
+
* (`platform.env.KV.<namespace>`); when no platform bindings exist (e.g.
|
|
11
|
+
* `astro dev` running in plain Node), it falls back to an in-memory Map so
|
|
12
|
+
* sessions still work during local development.
|
|
13
|
+
*/
|
|
14
|
+
interface SessionDriver {
|
|
15
|
+
getItem: (key: string) => Promise<any>;
|
|
16
|
+
setItem: (key: string, value: any) => Promise<void>;
|
|
17
|
+
removeItem: (key: string) => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface MaravillaSessionDriverConfig {
|
|
20
|
+
/** KV namespace to store sessions in (default: 'astro_sessions') */
|
|
21
|
+
namespace?: string;
|
|
22
|
+
/** TTL in seconds applied to each session entry on write */
|
|
23
|
+
ttl?: number;
|
|
24
|
+
}
|
|
25
|
+
export default function maravillaSessionDriver(config?: MaravillaSessionDriverConfig): SessionDriver;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=session-driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-driver.d.ts","sourceRoot":"","sources":["../src/session-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,UAAU,aAAa;IACrB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACvC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,4BAA4B;IAC3C,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AA6BD,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,MAAM,CAAC,EAAE,4BAA4B,GACpC,aAAa,CA+Bf"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KV-backed Astro session driver for Maravilla Runtime.
|
|
3
|
+
*
|
|
4
|
+
* Astro sessions are backed by a minimal unstorage-shaped driver
|
|
5
|
+
* (`getItem`/`setItem`/`removeItem` — see astro/dist/core/session/types.d.ts).
|
|
6
|
+
* The adapter wires this module as the default `session.driver` entrypoint so
|
|
7
|
+
* `Astro.session` works out of the box.
|
|
8
|
+
*
|
|
9
|
+
* In production the driver persists to the platform KV store
|
|
10
|
+
* (`platform.env.KV.<namespace>`); when no platform bindings exist (e.g.
|
|
11
|
+
* `astro dev` running in plain Node), it falls back to an in-memory Map so
|
|
12
|
+
* sessions still work during local development.
|
|
13
|
+
*/
|
|
14
|
+
const memoryStore = new Map();
|
|
15
|
+
let warnedAboutMemoryFallback = false;
|
|
16
|
+
/** `astro dev` runs the driver in plain Node, where the fallback is expected. */
|
|
17
|
+
function isAstroDev() {
|
|
18
|
+
return globalThis.process?.env?.NODE_ENV === 'development';
|
|
19
|
+
}
|
|
20
|
+
function kvNamespace(namespace) {
|
|
21
|
+
const platform = globalThis.platform;
|
|
22
|
+
const kv = platform?.env?.KV;
|
|
23
|
+
if (!kv) {
|
|
24
|
+
if (!warnedAboutMemoryFallback && !isAstroDev()) {
|
|
25
|
+
warnedAboutMemoryFallback = true;
|
|
26
|
+
console.warn('[maravilla] No platform KV binding found; Astro sessions are falling back to ' +
|
|
27
|
+
'per-isolate in-memory storage. Sessions will be lost when a worker recycles and ' +
|
|
28
|
+
'are not shared across workers. Check that the KV binding is configured for this ' +
|
|
29
|
+
'deployment.');
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return kv[namespace];
|
|
34
|
+
}
|
|
35
|
+
export default function maravillaSessionDriver(config) {
|
|
36
|
+
const namespace = config?.namespace ?? 'astro_sessions';
|
|
37
|
+
const ttl = config?.ttl;
|
|
38
|
+
return {
|
|
39
|
+
async getItem(key) {
|
|
40
|
+
const kv = kvNamespace(namespace);
|
|
41
|
+
if (!kv)
|
|
42
|
+
return memoryStore.get(key) ?? null;
|
|
43
|
+
const value = await kv.get(key);
|
|
44
|
+
return value ?? null;
|
|
45
|
+
},
|
|
46
|
+
async setItem(key, value) {
|
|
47
|
+
const serialized = typeof value === 'string' ? value : JSON.stringify(value);
|
|
48
|
+
const kv = kvNamespace(namespace);
|
|
49
|
+
if (!kv) {
|
|
50
|
+
memoryStore.set(key, serialized);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
await kv.put(key, serialized, ttl ? { expirationTtl: ttl } : undefined);
|
|
54
|
+
},
|
|
55
|
+
async removeItem(key) {
|
|
56
|
+
const kv = kvNamespace(namespace);
|
|
57
|
+
if (!kv) {
|
|
58
|
+
memoryStore.delete(key);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
await kv.delete(key);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=session-driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-driver.js","sourceRoot":"","sources":["../src/session-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAeH,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE9C,IAAI,yBAAyB,GAAG,KAAK,CAAC;AAEtC,iFAAiF;AACjF,SAAS,UAAU;IACjB,OAAQ,UAAkC,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,aAAa,CAAC;AACtF,CAAC;AAED,SAAS,WAAW,CAAC,SAAiB;IACpC,MAAM,QAAQ,GAAI,UAAkC,CAAC,QAAQ,CAAC;IAC9D,MAAM,EAAE,GAAG,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC;IAC7B,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,IAAI,CAAC,yBAAyB,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YAChD,yBAAyB,GAAG,IAAI,CAAC;YACjC,OAAO,CAAC,IAAI,CACV,+EAA+E;gBAC7E,kFAAkF;gBAClF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AAC,EAAE,EAAE,CAAC;gBACR,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACxB,OAAO;YACT,CAAC;YACD,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal `node:buffer` shim over web APIs for the Maravilla isolate.
|
|
3
|
+
* Supports the subset Astro's server internals use: from/alloc/concat,
|
|
4
|
+
* isBuffer, byteLength and toString for utf8/base64/hex.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Buffer extends Uint8Array {
|
|
7
|
+
toString(encoding?: string): string;
|
|
8
|
+
}
|
|
9
|
+
export declare const constants: {
|
|
10
|
+
MAX_LENGTH: number;
|
|
11
|
+
MAX_STRING_LENGTH: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function isUtf8(): boolean;
|
|
14
|
+
declare const _default: {
|
|
15
|
+
Buffer: typeof Buffer;
|
|
16
|
+
constants: {
|
|
17
|
+
MAX_LENGTH: number;
|
|
18
|
+
MAX_STRING_LENGTH: number;
|
|
19
|
+
};
|
|
20
|
+
isUtf8: typeof isUtf8;
|
|
21
|
+
};
|
|
22
|
+
export default _default;
|
|
23
|
+
//# sourceMappingURL=buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../src/shims/buffer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkCH,qBAAa,MAAO,SAAQ,UAAU;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;CAYpC;AA2CD,eAAO,MAAM,SAAS;;;CAA+D,CAAC;AAEtF,wBAAgB,MAAM,IAAI,OAAO,CAEhC;;;;;;;;;AAED,wBAA6C"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal `node:buffer` shim over web APIs for the Maravilla isolate.
|
|
3
|
+
* Supports the subset Astro's server internals use: from/alloc/concat,
|
|
4
|
+
* isBuffer, byteLength and toString for utf8/base64/hex.
|
|
5
|
+
*/
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
const decoder = new TextDecoder();
|
|
9
|
+
function fromBase64(input) {
|
|
10
|
+
const binary = atob(input.replace(/-/g, '+').replace(/_/g, '/'));
|
|
11
|
+
const bytes = new Uint8Array(binary.length);
|
|
12
|
+
for (let i = 0; i < binary.length; i++)
|
|
13
|
+
bytes[i] = binary.charCodeAt(i);
|
|
14
|
+
return bytes;
|
|
15
|
+
}
|
|
16
|
+
function toBase64(bytes) {
|
|
17
|
+
let binary = '';
|
|
18
|
+
for (let i = 0; i < bytes.length; i++)
|
|
19
|
+
binary += String.fromCharCode(bytes[i]);
|
|
20
|
+
return btoa(binary);
|
|
21
|
+
}
|
|
22
|
+
function fromHex(input) {
|
|
23
|
+
const bytes = new Uint8Array(input.length / 2);
|
|
24
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
25
|
+
bytes[i] = parseInt(input.substr(i * 2, 2), 16);
|
|
26
|
+
}
|
|
27
|
+
return bytes;
|
|
28
|
+
}
|
|
29
|
+
function toHex(bytes) {
|
|
30
|
+
let out = '';
|
|
31
|
+
for (let i = 0; i < bytes.length; i++)
|
|
32
|
+
out += bytes[i].toString(16).padStart(2, '0');
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
export class Buffer extends Uint8Array {
|
|
36
|
+
toString(encoding) {
|
|
37
|
+
switch (encoding) {
|
|
38
|
+
case 'base64':
|
|
39
|
+
return toBase64(this);
|
|
40
|
+
case 'base64url':
|
|
41
|
+
return toBase64(this).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
42
|
+
case 'hex':
|
|
43
|
+
return toHex(this);
|
|
44
|
+
default:
|
|
45
|
+
return decoder.decode(this);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function bufferFrom(input, encoding) {
|
|
50
|
+
if (typeof input === 'string') {
|
|
51
|
+
switch (encoding) {
|
|
52
|
+
case 'base64':
|
|
53
|
+
case 'base64url':
|
|
54
|
+
return new Buffer(fromBase64(input));
|
|
55
|
+
case 'hex':
|
|
56
|
+
return new Buffer(fromHex(input));
|
|
57
|
+
default:
|
|
58
|
+
return new Buffer(encoder.encode(input));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (input instanceof ArrayBuffer)
|
|
62
|
+
return new Buffer(new Uint8Array(input));
|
|
63
|
+
if (ArrayBuffer.isView(input)) {
|
|
64
|
+
return new Buffer(new Uint8Array(input.buffer, input.byteOffset, input.byteLength));
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(input))
|
|
67
|
+
return new Buffer(Uint8Array.from(input));
|
|
68
|
+
throw new TypeError('Unsupported Buffer.from input in Maravilla buffer shim');
|
|
69
|
+
}
|
|
70
|
+
// Assigned outside the class body: the encoding-aware `from(input, encoding)`
|
|
71
|
+
// signature is incompatible with `Uint8Array.from(arrayLike, mapfn)`.
|
|
72
|
+
Object.assign(Buffer, {
|
|
73
|
+
from: bufferFrom,
|
|
74
|
+
alloc: (size) => new Buffer(size),
|
|
75
|
+
allocUnsafe: (size) => new Buffer(size),
|
|
76
|
+
isBuffer: (value) => value instanceof Buffer,
|
|
77
|
+
byteLength: (input, encoding) => bufferFrom(input, encoding).length,
|
|
78
|
+
concat: (buffers, totalLength) => {
|
|
79
|
+
const length = totalLength ?? buffers.reduce((sum, b) => sum + b.length, 0);
|
|
80
|
+
const out = new Buffer(length);
|
|
81
|
+
let offset = 0;
|
|
82
|
+
for (const b of buffers) {
|
|
83
|
+
out.set(b.subarray(0, Math.max(0, length - offset)), offset);
|
|
84
|
+
offset += b.length;
|
|
85
|
+
if (offset >= length)
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
export const constants = { MAX_LENGTH: 2 ** 31 - 1, MAX_STRING_LENGTH: 2 ** 29 - 24 };
|
|
92
|
+
export function isUtf8() {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
export default { Buffer, constants, isUtf8 };
|
|
96
|
+
//# sourceMappingURL=buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../src/shims/buffer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,uDAAuD;AAEvD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACxE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,KAAiB;IACjC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,OAAO,CAAC,KAAa;IAC5B,MAAM,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