@eldrin-project/eldrin-app-core 0.0.3 → 0.0.4
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/dist/index.cjs +0 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -168
- package/dist/index.d.ts +1 -168
- package/dist/index.js +1 -119
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* Core types for @eldrin-project/eldrin-app-core
|
|
6
3
|
*/
|
|
@@ -145,170 +142,6 @@ interface AppManifest {
|
|
|
145
142
|
*/
|
|
146
143
|
groups?: ManifestGroup[];
|
|
147
144
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Options for createApp factory
|
|
150
|
-
*/
|
|
151
|
-
interface CreateAppOptions {
|
|
152
|
-
/** Unique app identifier */
|
|
153
|
-
name: string;
|
|
154
|
-
/** Root React component */
|
|
155
|
-
root: React.ComponentType<unknown>;
|
|
156
|
-
/** App manifest (optional, can be loaded from file) */
|
|
157
|
-
manifest?: AppManifest;
|
|
158
|
-
/** Migration files (loaded at build time via Vite plugin) */
|
|
159
|
-
migrations?: MigrationFile[];
|
|
160
|
-
/** Called when migrations complete successfully */
|
|
161
|
-
onMigrationsComplete?: (result: MigrationResult) => void;
|
|
162
|
-
/** Called when migrations fail */
|
|
163
|
-
onMigrationError?: (error: Error) => void;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Database context passed to app components
|
|
167
|
-
*/
|
|
168
|
-
interface DatabaseContext {
|
|
169
|
-
/** D1 database instance (null if app has no database) */
|
|
170
|
-
db: D1Database | null;
|
|
171
|
-
/** Whether migrations have completed */
|
|
172
|
-
migrationsComplete: boolean;
|
|
173
|
-
/** Migration result (if migrations were run) */
|
|
174
|
-
migrationResult?: MigrationResult;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Eldrin context provided to apps
|
|
178
|
-
*/
|
|
179
|
-
interface EldrinContext {
|
|
180
|
-
/** App ID */
|
|
181
|
-
appId: string;
|
|
182
|
-
/** Database context */
|
|
183
|
-
database: DatabaseContext;
|
|
184
|
-
/** Environment variables */
|
|
185
|
-
env: Record<string, string>;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* App factory for creating Eldrin apps
|
|
190
|
-
*
|
|
191
|
-
* Returns single-spa compatible lifecycle functions with:
|
|
192
|
-
* - Automatic migration execution on bootstrap
|
|
193
|
-
* - Database provider wrapping
|
|
194
|
-
* - Error boundary integration
|
|
195
|
-
*/
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Single-spa lifecycle props passed to lifecycle functions
|
|
199
|
-
*/
|
|
200
|
-
interface LifecycleProps {
|
|
201
|
-
/** DOM element to mount the app into */
|
|
202
|
-
domElement?: HTMLElement;
|
|
203
|
-
/** App name */
|
|
204
|
-
name?: string;
|
|
205
|
-
/** D1 Database instance (provided by shell) */
|
|
206
|
-
db?: D1Database;
|
|
207
|
-
/** Custom props from shell */
|
|
208
|
-
customProps?: Record<string, unknown>;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Single-spa compatible lifecycle object
|
|
212
|
-
*/
|
|
213
|
-
interface AppLifecycle {
|
|
214
|
-
bootstrap: (props: LifecycleProps) => Promise<void>;
|
|
215
|
-
mount: (props: LifecycleProps) => Promise<void>;
|
|
216
|
-
unmount: (props: LifecycleProps) => Promise<void>;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Create an Eldrin app with single-spa compatible lifecycle
|
|
220
|
-
*
|
|
221
|
-
* @param options - App configuration
|
|
222
|
-
* @returns Object with bootstrap, mount, and unmount lifecycle functions
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```tsx
|
|
226
|
-
* // src/index.tsx
|
|
227
|
-
* import { createApp } from '@eldrin-project/eldrin-app-core';
|
|
228
|
-
* import App from './App';
|
|
229
|
-
*
|
|
230
|
-
* export const { bootstrap, mount, unmount } = createApp({
|
|
231
|
-
* name: 'invoicing',
|
|
232
|
-
* root: App,
|
|
233
|
-
* // Migrations loaded via Vite plugin
|
|
234
|
-
* });
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
declare function createApp(options: CreateAppOptions): AppLifecycle;
|
|
238
|
-
/**
|
|
239
|
-
* Type helper for migration files loaded via Vite plugin
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```tsx
|
|
243
|
-
* // With Vite plugin
|
|
244
|
-
* import { createApp, type MigrationFiles } from '@eldrin-project/eldrin-app-core';
|
|
245
|
-
* import migrations from 'virtual:eldrin/migrations';
|
|
246
|
-
*
|
|
247
|
-
* export const { bootstrap, mount, unmount } = createApp({
|
|
248
|
-
* name: 'invoicing',
|
|
249
|
-
* root: App,
|
|
250
|
-
* migrations: migrations as MigrationFiles,
|
|
251
|
-
* });
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
type MigrationFiles = MigrationFile[];
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Props for DatabaseProvider
|
|
258
|
-
*/
|
|
259
|
-
interface DatabaseProviderProps {
|
|
260
|
-
/** D1 database instance (null if app has no database) */
|
|
261
|
-
db: D1Database | null;
|
|
262
|
-
/** Whether migrations have completed */
|
|
263
|
-
migrationsComplete: boolean;
|
|
264
|
-
/** Migration result */
|
|
265
|
-
migrationResult?: MigrationResult;
|
|
266
|
-
/** Child components */
|
|
267
|
-
children: ReactNode;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Provider component for database context
|
|
271
|
-
*/
|
|
272
|
-
declare function DatabaseProvider({ db, migrationsComplete, migrationResult, children, }: DatabaseProviderProps): react_jsx_runtime.JSX.Element;
|
|
273
|
-
/**
|
|
274
|
-
* Hook to access the app's D1 database
|
|
275
|
-
*
|
|
276
|
-
* @returns D1Database instance or null if app has no database
|
|
277
|
-
* @throws Error if used outside of DatabaseProvider
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```tsx
|
|
281
|
-
* function InvoiceList() {
|
|
282
|
-
* const db = useDatabase();
|
|
283
|
-
*
|
|
284
|
-
* if (!db) {
|
|
285
|
-
* return <div>No database configured</div>;
|
|
286
|
-
* }
|
|
287
|
-
*
|
|
288
|
-
* const { results } = await db.prepare(
|
|
289
|
-
* 'SELECT * FROM invoices ORDER BY created_at DESC'
|
|
290
|
-
* ).all();
|
|
291
|
-
*
|
|
292
|
-
* return <div>{results.map(invoice => ...)}</div>;
|
|
293
|
-
* }
|
|
294
|
-
* ```
|
|
295
|
-
*/
|
|
296
|
-
declare function useDatabase(): D1Database | null;
|
|
297
|
-
/**
|
|
298
|
-
* Hook to access full database context including migration status
|
|
299
|
-
*
|
|
300
|
-
* @returns DatabaseContext object
|
|
301
|
-
* @throws Error if used outside of DatabaseProvider
|
|
302
|
-
*/
|
|
303
|
-
declare function useDatabaseContext(): DatabaseContext;
|
|
304
|
-
/**
|
|
305
|
-
* Hook to check if migrations have completed
|
|
306
|
-
*
|
|
307
|
-
* Useful for showing loading states while migrations run
|
|
308
|
-
*
|
|
309
|
-
* @returns true if migrations are complete
|
|
310
|
-
*/
|
|
311
|
-
declare function useMigrationsComplete(): boolean;
|
|
312
145
|
|
|
313
146
|
/**
|
|
314
147
|
* Migration runner for Eldrin apps
|
|
@@ -1304,4 +1137,4 @@ declare function isPublicRoute(pathname: string, publicRoutes: string[], apiPref
|
|
|
1304
1137
|
*/
|
|
1305
1138
|
declare function createPermissionMiddleware<TEnv = unknown>(config: MiddlewareConfig<TEnv>): PermissionMiddleware<TEnv>;
|
|
1306
1139
|
|
|
1307
|
-
export { AUTH_HEADERS, type AppAuthContext, type
|
|
1140
|
+
export { AUTH_HEADERS, type AppAuthContext, type AppManifest, CHECKSUM_PREFIX, type CompiledRoute, type CorsConfig, type EldrinEnv, type EldrinEvent, EldrinEventClient, type EmitOptions, type EmitResult, type EventClientConfig, type EventDelivery, type EventHandler, type GenerateMigrationManifestOptions, type GenerateMigrationManifestResult, type JWTPayload, type JWTVerifyOptions, type ManifestApi, type ManifestForMiddleware, type ManifestGroup, type ManifestPermission, type ManifestRoute, type MiddlewareAuthResult, type MiddlewareConfig, type MiddlewareError, type MiddlewareErrorType, type MiddlewareResponseResult, type MiddlewareResult, type MigrationFile, type MigrationManifest, type MigrationManifestEntry, type MigrationOptions, type MigrationRecord, type MigrationResult, type PermissionMiddleware, type PollOptions, type PollResult, type RegisteredEventType, type RollbackResult, type SubscriptionInfo, calculateChecksum, calculatePrefixedChecksum, compileRoutes, createEventClient, createPermissionMiddleware, extractTimestamp, generateMigrationManifest, getAuthContext, getAuthContextFromJWT, getMigrationStatus, getRollbackFilename, hasPermission, hasPlatformRole, isPlatformAdmin, isPublicRoute, isValidMigrationFilename, isValidRollbackFilename, matchRoute, parseSQLStatements, requireAllPermissions, requireAnyPermission, requireAuth, requireJWTAuth, requireJWTPermission, requirePermission, rollbackMigrations, runMigrations, validateMigrationManifest, verifyChecksum, verifyJWT };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* Core types for @eldrin-project/eldrin-app-core
|
|
6
3
|
*/
|
|
@@ -145,170 +142,6 @@ interface AppManifest {
|
|
|
145
142
|
*/
|
|
146
143
|
groups?: ManifestGroup[];
|
|
147
144
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Options for createApp factory
|
|
150
|
-
*/
|
|
151
|
-
interface CreateAppOptions {
|
|
152
|
-
/** Unique app identifier */
|
|
153
|
-
name: string;
|
|
154
|
-
/** Root React component */
|
|
155
|
-
root: React.ComponentType<unknown>;
|
|
156
|
-
/** App manifest (optional, can be loaded from file) */
|
|
157
|
-
manifest?: AppManifest;
|
|
158
|
-
/** Migration files (loaded at build time via Vite plugin) */
|
|
159
|
-
migrations?: MigrationFile[];
|
|
160
|
-
/** Called when migrations complete successfully */
|
|
161
|
-
onMigrationsComplete?: (result: MigrationResult) => void;
|
|
162
|
-
/** Called when migrations fail */
|
|
163
|
-
onMigrationError?: (error: Error) => void;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Database context passed to app components
|
|
167
|
-
*/
|
|
168
|
-
interface DatabaseContext {
|
|
169
|
-
/** D1 database instance (null if app has no database) */
|
|
170
|
-
db: D1Database | null;
|
|
171
|
-
/** Whether migrations have completed */
|
|
172
|
-
migrationsComplete: boolean;
|
|
173
|
-
/** Migration result (if migrations were run) */
|
|
174
|
-
migrationResult?: MigrationResult;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Eldrin context provided to apps
|
|
178
|
-
*/
|
|
179
|
-
interface EldrinContext {
|
|
180
|
-
/** App ID */
|
|
181
|
-
appId: string;
|
|
182
|
-
/** Database context */
|
|
183
|
-
database: DatabaseContext;
|
|
184
|
-
/** Environment variables */
|
|
185
|
-
env: Record<string, string>;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* App factory for creating Eldrin apps
|
|
190
|
-
*
|
|
191
|
-
* Returns single-spa compatible lifecycle functions with:
|
|
192
|
-
* - Automatic migration execution on bootstrap
|
|
193
|
-
* - Database provider wrapping
|
|
194
|
-
* - Error boundary integration
|
|
195
|
-
*/
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Single-spa lifecycle props passed to lifecycle functions
|
|
199
|
-
*/
|
|
200
|
-
interface LifecycleProps {
|
|
201
|
-
/** DOM element to mount the app into */
|
|
202
|
-
domElement?: HTMLElement;
|
|
203
|
-
/** App name */
|
|
204
|
-
name?: string;
|
|
205
|
-
/** D1 Database instance (provided by shell) */
|
|
206
|
-
db?: D1Database;
|
|
207
|
-
/** Custom props from shell */
|
|
208
|
-
customProps?: Record<string, unknown>;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Single-spa compatible lifecycle object
|
|
212
|
-
*/
|
|
213
|
-
interface AppLifecycle {
|
|
214
|
-
bootstrap: (props: LifecycleProps) => Promise<void>;
|
|
215
|
-
mount: (props: LifecycleProps) => Promise<void>;
|
|
216
|
-
unmount: (props: LifecycleProps) => Promise<void>;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Create an Eldrin app with single-spa compatible lifecycle
|
|
220
|
-
*
|
|
221
|
-
* @param options - App configuration
|
|
222
|
-
* @returns Object with bootstrap, mount, and unmount lifecycle functions
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```tsx
|
|
226
|
-
* // src/index.tsx
|
|
227
|
-
* import { createApp } from '@eldrin-project/eldrin-app-core';
|
|
228
|
-
* import App from './App';
|
|
229
|
-
*
|
|
230
|
-
* export const { bootstrap, mount, unmount } = createApp({
|
|
231
|
-
* name: 'invoicing',
|
|
232
|
-
* root: App,
|
|
233
|
-
* // Migrations loaded via Vite plugin
|
|
234
|
-
* });
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
declare function createApp(options: CreateAppOptions): AppLifecycle;
|
|
238
|
-
/**
|
|
239
|
-
* Type helper for migration files loaded via Vite plugin
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```tsx
|
|
243
|
-
* // With Vite plugin
|
|
244
|
-
* import { createApp, type MigrationFiles } from '@eldrin-project/eldrin-app-core';
|
|
245
|
-
* import migrations from 'virtual:eldrin/migrations';
|
|
246
|
-
*
|
|
247
|
-
* export const { bootstrap, mount, unmount } = createApp({
|
|
248
|
-
* name: 'invoicing',
|
|
249
|
-
* root: App,
|
|
250
|
-
* migrations: migrations as MigrationFiles,
|
|
251
|
-
* });
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
type MigrationFiles = MigrationFile[];
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Props for DatabaseProvider
|
|
258
|
-
*/
|
|
259
|
-
interface DatabaseProviderProps {
|
|
260
|
-
/** D1 database instance (null if app has no database) */
|
|
261
|
-
db: D1Database | null;
|
|
262
|
-
/** Whether migrations have completed */
|
|
263
|
-
migrationsComplete: boolean;
|
|
264
|
-
/** Migration result */
|
|
265
|
-
migrationResult?: MigrationResult;
|
|
266
|
-
/** Child components */
|
|
267
|
-
children: ReactNode;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Provider component for database context
|
|
271
|
-
*/
|
|
272
|
-
declare function DatabaseProvider({ db, migrationsComplete, migrationResult, children, }: DatabaseProviderProps): react_jsx_runtime.JSX.Element;
|
|
273
|
-
/**
|
|
274
|
-
* Hook to access the app's D1 database
|
|
275
|
-
*
|
|
276
|
-
* @returns D1Database instance or null if app has no database
|
|
277
|
-
* @throws Error if used outside of DatabaseProvider
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```tsx
|
|
281
|
-
* function InvoiceList() {
|
|
282
|
-
* const db = useDatabase();
|
|
283
|
-
*
|
|
284
|
-
* if (!db) {
|
|
285
|
-
* return <div>No database configured</div>;
|
|
286
|
-
* }
|
|
287
|
-
*
|
|
288
|
-
* const { results } = await db.prepare(
|
|
289
|
-
* 'SELECT * FROM invoices ORDER BY created_at DESC'
|
|
290
|
-
* ).all();
|
|
291
|
-
*
|
|
292
|
-
* return <div>{results.map(invoice => ...)}</div>;
|
|
293
|
-
* }
|
|
294
|
-
* ```
|
|
295
|
-
*/
|
|
296
|
-
declare function useDatabase(): D1Database | null;
|
|
297
|
-
/**
|
|
298
|
-
* Hook to access full database context including migration status
|
|
299
|
-
*
|
|
300
|
-
* @returns DatabaseContext object
|
|
301
|
-
* @throws Error if used outside of DatabaseProvider
|
|
302
|
-
*/
|
|
303
|
-
declare function useDatabaseContext(): DatabaseContext;
|
|
304
|
-
/**
|
|
305
|
-
* Hook to check if migrations have completed
|
|
306
|
-
*
|
|
307
|
-
* Useful for showing loading states while migrations run
|
|
308
|
-
*
|
|
309
|
-
* @returns true if migrations are complete
|
|
310
|
-
*/
|
|
311
|
-
declare function useMigrationsComplete(): boolean;
|
|
312
145
|
|
|
313
146
|
/**
|
|
314
147
|
* Migration runner for Eldrin apps
|
|
@@ -1304,4 +1137,4 @@ declare function isPublicRoute(pathname: string, publicRoutes: string[], apiPref
|
|
|
1304
1137
|
*/
|
|
1305
1138
|
declare function createPermissionMiddleware<TEnv = unknown>(config: MiddlewareConfig<TEnv>): PermissionMiddleware<TEnv>;
|
|
1306
1139
|
|
|
1307
|
-
export { AUTH_HEADERS, type AppAuthContext, type
|
|
1140
|
+
export { AUTH_HEADERS, type AppAuthContext, type AppManifest, CHECKSUM_PREFIX, type CompiledRoute, type CorsConfig, type EldrinEnv, type EldrinEvent, EldrinEventClient, type EmitOptions, type EmitResult, type EventClientConfig, type EventDelivery, type EventHandler, type GenerateMigrationManifestOptions, type GenerateMigrationManifestResult, type JWTPayload, type JWTVerifyOptions, type ManifestApi, type ManifestForMiddleware, type ManifestGroup, type ManifestPermission, type ManifestRoute, type MiddlewareAuthResult, type MiddlewareConfig, type MiddlewareError, type MiddlewareErrorType, type MiddlewareResponseResult, type MiddlewareResult, type MigrationFile, type MigrationManifest, type MigrationManifestEntry, type MigrationOptions, type MigrationRecord, type MigrationResult, type PermissionMiddleware, type PollOptions, type PollResult, type RegisteredEventType, type RollbackResult, type SubscriptionInfo, calculateChecksum, calculatePrefixedChecksum, compileRoutes, createEventClient, createPermissionMiddleware, extractTimestamp, generateMigrationManifest, getAuthContext, getAuthContextFromJWT, getMigrationStatus, getRollbackFilename, hasPermission, hasPlatformRole, isPlatformAdmin, isPublicRoute, isValidMigrationFilename, isValidRollbackFilename, matchRoute, parseSQLStatements, requireAllPermissions, requireAnyPermission, requireAuth, requireJWTAuth, requireJWTPermission, requirePermission, rollbackMigrations, runMigrations, validateMigrationManifest, verifyChecksum, verifyJWT };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { createContext, useContext, createElement } from 'react';
|
|
2
1
|
import { readdir, readFile } from 'fs/promises';
|
|
3
2
|
import { existsSync } from 'fs';
|
|
4
3
|
import { resolve, basename } from 'path';
|
|
5
|
-
import { jsx } from 'react/jsx-runtime';
|
|
6
|
-
|
|
7
|
-
// src/app/createApp.tsx
|
|
8
4
|
|
|
9
5
|
// src/migrations/checksum.ts
|
|
10
6
|
var CHECKSUM_PREFIX = "sha256:";
|
|
@@ -442,120 +438,6 @@ async function validateMigrationManifest(manifest, files) {
|
|
|
442
438
|
errors
|
|
443
439
|
};
|
|
444
440
|
}
|
|
445
|
-
var EldrinDatabaseContext = createContext(null);
|
|
446
|
-
function DatabaseProvider({
|
|
447
|
-
db,
|
|
448
|
-
migrationsComplete,
|
|
449
|
-
migrationResult,
|
|
450
|
-
children
|
|
451
|
-
}) {
|
|
452
|
-
const value = {
|
|
453
|
-
db,
|
|
454
|
-
migrationsComplete,
|
|
455
|
-
migrationResult
|
|
456
|
-
};
|
|
457
|
-
return /* @__PURE__ */ jsx(EldrinDatabaseContext.Provider, { value, children });
|
|
458
|
-
}
|
|
459
|
-
function useDatabase() {
|
|
460
|
-
const context = useContext(EldrinDatabaseContext);
|
|
461
|
-
if (context === null) {
|
|
462
|
-
throw new Error("useDatabase must be used within a DatabaseProvider (via createApp)");
|
|
463
|
-
}
|
|
464
|
-
return context.db;
|
|
465
|
-
}
|
|
466
|
-
function useDatabaseContext() {
|
|
467
|
-
const context = useContext(EldrinDatabaseContext);
|
|
468
|
-
if (context === null) {
|
|
469
|
-
throw new Error("useDatabaseContext must be used within a DatabaseProvider (via createApp)");
|
|
470
|
-
}
|
|
471
|
-
return context;
|
|
472
|
-
}
|
|
473
|
-
function useMigrationsComplete() {
|
|
474
|
-
const context = useContext(EldrinDatabaseContext);
|
|
475
|
-
return context?.migrationsComplete ?? false;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
// src/app/createApp.tsx
|
|
479
|
-
function createApp(options) {
|
|
480
|
-
const { name, root: RootComponent, migrations = [], onMigrationsComplete, onMigrationError } = options;
|
|
481
|
-
const state = {
|
|
482
|
-
db: null,
|
|
483
|
-
migrationsComplete: false,
|
|
484
|
-
migrationResult: void 0,
|
|
485
|
-
mountedElement: void 0,
|
|
486
|
-
reactRoot: void 0
|
|
487
|
-
};
|
|
488
|
-
async function bootstrap(props) {
|
|
489
|
-
const db = props.db ?? null;
|
|
490
|
-
state.db = db;
|
|
491
|
-
if (db && migrations.length > 0) {
|
|
492
|
-
try {
|
|
493
|
-
const result = await runMigrations(db, {
|
|
494
|
-
migrations,
|
|
495
|
-
onLog: (message, level) => {
|
|
496
|
-
const prefix = `[${name}]`;
|
|
497
|
-
if (level === "error") {
|
|
498
|
-
console.error(prefix, message);
|
|
499
|
-
} else if (level === "warn") {
|
|
500
|
-
console.warn(prefix, message);
|
|
501
|
-
} else {
|
|
502
|
-
console.log(prefix, message);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
state.migrationResult = result;
|
|
507
|
-
if (result.success) {
|
|
508
|
-
state.migrationsComplete = true;
|
|
509
|
-
onMigrationsComplete?.(result);
|
|
510
|
-
} else {
|
|
511
|
-
const error = new Error(result.error?.message ?? "Migration failed");
|
|
512
|
-
onMigrationError?.(error);
|
|
513
|
-
throw error;
|
|
514
|
-
}
|
|
515
|
-
} catch (error) {
|
|
516
|
-
state.migrationsComplete = false;
|
|
517
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
518
|
-
onMigrationError?.(err);
|
|
519
|
-
throw err;
|
|
520
|
-
}
|
|
521
|
-
} else {
|
|
522
|
-
state.migrationsComplete = true;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
async function mount(props) {
|
|
526
|
-
const domElement = props.domElement ?? document.getElementById(`app-${name}`);
|
|
527
|
-
if (!domElement) {
|
|
528
|
-
throw new Error(`No DOM element found for app "${name}". Expected element with id="app-${name}" or domElement prop.`);
|
|
529
|
-
}
|
|
530
|
-
state.mountedElement = domElement;
|
|
531
|
-
const rootElement = createElement(RootComponent, props.customProps ?? {});
|
|
532
|
-
const appElement = createElement(DatabaseProvider, {
|
|
533
|
-
db: state.db,
|
|
534
|
-
migrationsComplete: state.migrationsComplete,
|
|
535
|
-
migrationResult: state.migrationResult,
|
|
536
|
-
children: rootElement
|
|
537
|
-
});
|
|
538
|
-
const ReactDOM = await import('react-dom/client');
|
|
539
|
-
const root = ReactDOM.createRoot(domElement);
|
|
540
|
-
root.render(appElement);
|
|
541
|
-
state.reactRoot = root;
|
|
542
|
-
}
|
|
543
|
-
async function unmount(_props) {
|
|
544
|
-
if (state.reactRoot) {
|
|
545
|
-
state.reactRoot.unmount();
|
|
546
|
-
state.reactRoot = void 0;
|
|
547
|
-
}
|
|
548
|
-
if (state.mountedElement) {
|
|
549
|
-
state.mountedElement.innerHTML = "";
|
|
550
|
-
state.mountedElement = void 0;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
return {
|
|
554
|
-
bootstrap,
|
|
555
|
-
mount,
|
|
556
|
-
unmount
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
441
|
|
|
560
442
|
// src/events/client.ts
|
|
561
443
|
var EldrinEventClient = class {
|
|
@@ -1159,6 +1041,6 @@ function createPermissionMiddleware(config) {
|
|
|
1159
1041
|
};
|
|
1160
1042
|
}
|
|
1161
1043
|
|
|
1162
|
-
export { AUTH_HEADERS, CHECKSUM_PREFIX,
|
|
1044
|
+
export { AUTH_HEADERS, CHECKSUM_PREFIX, EldrinEventClient, calculateChecksum, calculatePrefixedChecksum, compileRoutes, createEventClient, createPermissionMiddleware, extractTimestamp, generateMigrationManifest, getAuthContext, getAuthContextFromJWT, getMigrationStatus, getRollbackFilename, hasPermission, hasPlatformRole, isPlatformAdmin, isPublicRoute, isValidMigrationFilename, isValidRollbackFilename, matchRoute, parseSQLStatements, requireAllPermissions, requireAnyPermission, requireAuth, requireJWTAuth, requireJWTPermission, requirePermission, rollbackMigrations, runMigrations, validateMigrationManifest, verifyChecksum, verifyJWT };
|
|
1163
1045
|
//# sourceMappingURL=index.js.map
|
|
1164
1046
|
//# sourceMappingURL=index.js.map
|