appflare 0.2.18 → 0.2.19

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.
@@ -1,9 +1,9 @@
1
1
  export function generateContextCreation(defaultR2Binding?: string): string {
2
2
  return `
3
- export function createSchedulerExecutionContext(
3
+ export async function createSchedulerExecutionContext(
4
4
  env: Record<string, unknown>,
5
5
  options: RegisterHandlersOptions,
6
- ): AppflareContext {
6
+ ): Promise<AppflareContext> {
7
7
  const database = env[options.databaseBinding] as D1Database;
8
8
  const r2Binding = options.r2Binding ?? ${JSON.stringify(defaultR2Binding ?? "")};
9
9
  const storageBucket = r2Binding
@@ -11,9 +11,17 @@ export function createSchedulerExecutionContext(
11
11
  : undefined;
12
12
  const db = createDb(database);
13
13
  const mutationEvents = [] as AppflareContext["mutationEvents"];
14
+ const kvNamespace = options.kvBinding
15
+ ? (env[options.kvBinding] as KVNamespace)
16
+ : undefined;
14
17
  const schedulerBinding = options.schedulerBinding ?? "APPFLARE_SCHEDULER_QUEUE";
15
18
  const schedulerQueue = env[schedulerBinding] as SchedulerQueueBinding | undefined;
16
19
  const helpers = createContextErrorHelpers();
20
+ const auth = createAuth({
21
+ DATABASE: database,
22
+ KV: kvNamespace,
23
+ });
24
+ const authAdapter = (await auth.$context).internalAdapter;
17
25
  const schedulerContext = {
18
26
  env: env as WorkerEnv["Bindings"],
19
27
  } as unknown as Context<WorkerEnv>;
@@ -27,6 +35,7 @@ export function createSchedulerExecutionContext(
27
35
  mutationEvents,
28
36
  user: null as never,
29
37
  session: null as never,
38
+ auth: authAdapter,
30
39
  context: schedulerContext,
31
40
  scheduler: createScheduler(schedulerQueue),
32
41
  storage: null as never,
@@ -60,6 +69,14 @@ export async function createExecutionContext(
60
69
  const schedulerBinding = options.schedulerBinding ?? "APPFLARE_SCHEDULER_QUEUE";
61
70
  const schedulerQueue = c.env[schedulerBinding] as SchedulerQueueBinding | undefined;
62
71
  const helpers = createContextErrorHelpers();
72
+ const auth = createAuth(
73
+ {
74
+ DATABASE: database,
75
+ KV: kvNamespace,
76
+ },
77
+ c.req.raw.cf as IncomingRequestCfProperties | undefined,
78
+ );
79
+ const authAdapter = (await auth.$context).internalAdapter;
63
80
  const ctx = {
64
81
  $db: db,
65
82
  db: createQueryDb(db, {
@@ -70,6 +87,7 @@ export async function createExecutionContext(
70
87
  mutationEvents,
71
88
  user,
72
89
  session,
90
+ auth: authAdapter,
73
91
  context: c,
74
92
  scheduler: createScheduler(schedulerQueue),
75
93
  storage: null as never,
@@ -13,7 +13,7 @@ export async function executeCronTriggers(
13
13
  return;
14
14
  }
15
15
 
16
- const ctx = createSchedulerExecutionContext(env, options);
16
+ const ctx = await createSchedulerExecutionContext(env, options);
17
17
 
18
18
  for (const cronEntry of cronHandlers) {
19
19
  if (!cronEntry.cronTriggers.includes(cronValue)) {
@@ -17,7 +17,7 @@ export async function executeScheduledBatch(
17
17
  return;
18
18
  }
19
19
 
20
- const ctx = createSchedulerExecutionContext(env, options);
20
+ const ctx = await createSchedulerExecutionContext(env, options);
21
21
 
22
22
  for (const message of batch.messages) {
23
23
  const body = (message?.body ?? {}) as QueueMessageBody;
@@ -1,5 +1,6 @@
1
1
  export function generateTypesContextSection(): string {
2
2
  return `type AuthSession = typeof auth.$Infer.Session;
3
+ type AuthAdapter = Awaited<typeof auth.$context>["internalAdapter"];
3
4
  type User = AuthSession['user']
4
5
  type Session = AuthSession['session']
5
6
 
@@ -55,6 +56,7 @@ export type AppflareContext = {
55
56
  mutationEvents: DbMutationEvent[];
56
57
  user: User;
57
58
  session: Session;
59
+ auth: AuthAdapter;
58
60
  context: Context<WorkerEnv>;
59
61
  scheduler: Scheduler;
60
62
  storage: AppflareStorage;
package/dist/cli/index.js CHANGED
@@ -1354,10 +1354,10 @@ function createStorageApi(
1354
1354
  };
1355
1355
  }
1356
1356
  `}function he(e){return `
1357
- export function createSchedulerExecutionContext(
1357
+ export async function createSchedulerExecutionContext(
1358
1358
  env: Record<string, unknown>,
1359
1359
  options: RegisterHandlersOptions,
1360
- ): AppflareContext {
1360
+ ): Promise<AppflareContext> {
1361
1361
  const database = env[options.databaseBinding] as D1Database;
1362
1362
  const r2Binding = options.r2Binding ?? ${JSON.stringify(e??"")};
1363
1363
  const storageBucket = r2Binding
@@ -1365,9 +1365,17 @@ export function createSchedulerExecutionContext(
1365
1365
  : undefined;
1366
1366
  const db = createDb(database);
1367
1367
  const mutationEvents = [] as AppflareContext["mutationEvents"];
1368
+ const kvNamespace = options.kvBinding
1369
+ ? (env[options.kvBinding] as KVNamespace)
1370
+ : undefined;
1368
1371
  const schedulerBinding = options.schedulerBinding ?? "APPFLARE_SCHEDULER_QUEUE";
1369
1372
  const schedulerQueue = env[schedulerBinding] as SchedulerQueueBinding | undefined;
1370
1373
  const helpers = createContextErrorHelpers();
1374
+ const auth = createAuth({
1375
+ DATABASE: database,
1376
+ KV: kvNamespace,
1377
+ });
1378
+ const authAdapter = (await auth.$context).internalAdapter;
1371
1379
  const schedulerContext = {
1372
1380
  env: env as WorkerEnv["Bindings"],
1373
1381
  } as unknown as Context<WorkerEnv>;
@@ -1381,6 +1389,7 @@ export function createSchedulerExecutionContext(
1381
1389
  mutationEvents,
1382
1390
  user: null as never,
1383
1391
  session: null as never,
1392
+ auth: authAdapter,
1384
1393
  context: schedulerContext,
1385
1394
  scheduler: createScheduler(schedulerQueue),
1386
1395
  storage: null as never,
@@ -1414,6 +1423,14 @@ export async function createExecutionContext(
1414
1423
  const schedulerBinding = options.schedulerBinding ?? "APPFLARE_SCHEDULER_QUEUE";
1415
1424
  const schedulerQueue = c.env[schedulerBinding] as SchedulerQueueBinding | undefined;
1416
1425
  const helpers = createContextErrorHelpers();
1426
+ const auth = createAuth(
1427
+ {
1428
+ DATABASE: database,
1429
+ KV: kvNamespace,
1430
+ },
1431
+ c.req.raw.cf as IncomingRequestCfProperties | undefined,
1432
+ );
1433
+ const authAdapter = (await auth.$context).internalAdapter;
1417
1434
  const ctx = {
1418
1435
  $db: db,
1419
1436
  db: createQueryDb(db, {
@@ -1424,6 +1441,7 @@ export async function createExecutionContext(
1424
1441
  mutationEvents,
1425
1442
  user,
1426
1443
  session,
1444
+ auth: authAdapter,
1427
1445
  context: c,
1428
1446
  scheduler: createScheduler(schedulerQueue),
1429
1447
  storage: null as never,
@@ -4296,6 +4314,7 @@ type TableInsertModel<TName extends TableName> = InferInsertModel<
4296
4314
  `}function Ce(){return [qe(),$e(),Ie(),Ae(),Ne()].join(`
4297
4315
 
4298
4316
  `)}function Me(){return `type AuthSession = typeof auth.$Infer.Session;
4317
+ type AuthAdapter = Awaited<typeof auth.$context>["internalAdapter"];
4299
4318
  type User = AuthSession['user']
4300
4319
  type Session = AuthSession['session']
4301
4320
 
@@ -4351,6 +4370,7 @@ export type AppflareContext = {
4351
4370
  mutationEvents: DbMutationEvent[];
4352
4371
  user: User;
4353
4372
  session: Session;
4373
+ auth: AuthAdapter;
4354
4374
  context: Context<WorkerEnv>;
4355
4375
  scheduler: Scheduler;
4356
4376
  storage: AppflareStorage;
@@ -5787,7 +5807,7 @@ export async function executeScheduledBatch(
5787
5807
  return;
5788
5808
  }
5789
5809
 
5790
- const ctx = createSchedulerExecutionContext(env, options);
5810
+ const ctx = await createSchedulerExecutionContext(env, options);
5791
5811
 
5792
5812
  for (const message of batch.messages) {
5793
5813
  const body = (message?.body ?? {}) as QueueMessageBody;
@@ -5838,7 +5858,7 @@ export async function executeCronTriggers(
5838
5858
  return;
5839
5859
  }
5840
5860
 
5841
- const ctx = createSchedulerExecutionContext(env, options);
5861
+ const ctx = await createSchedulerExecutionContext(env, options);
5842
5862
 
5843
5863
  for (const cronEntry of cronHandlers) {
5844
5864
  if (!cronEntry.cronTriggers.includes(cronValue)) {
@@ -1354,10 +1354,10 @@ function createStorageApi(
1354
1354
  };
1355
1355
  }
1356
1356
  `}function he(e){return `
1357
- export function createSchedulerExecutionContext(
1357
+ export async function createSchedulerExecutionContext(
1358
1358
  env: Record<string, unknown>,
1359
1359
  options: RegisterHandlersOptions,
1360
- ): AppflareContext {
1360
+ ): Promise<AppflareContext> {
1361
1361
  const database = env[options.databaseBinding] as D1Database;
1362
1362
  const r2Binding = options.r2Binding ?? ${JSON.stringify(e??"")};
1363
1363
  const storageBucket = r2Binding
@@ -1365,9 +1365,17 @@ export function createSchedulerExecutionContext(
1365
1365
  : undefined;
1366
1366
  const db = createDb(database);
1367
1367
  const mutationEvents = [] as AppflareContext["mutationEvents"];
1368
+ const kvNamespace = options.kvBinding
1369
+ ? (env[options.kvBinding] as KVNamespace)
1370
+ : undefined;
1368
1371
  const schedulerBinding = options.schedulerBinding ?? "APPFLARE_SCHEDULER_QUEUE";
1369
1372
  const schedulerQueue = env[schedulerBinding] as SchedulerQueueBinding | undefined;
1370
1373
  const helpers = createContextErrorHelpers();
1374
+ const auth = createAuth({
1375
+ DATABASE: database,
1376
+ KV: kvNamespace,
1377
+ });
1378
+ const authAdapter = (await auth.$context).internalAdapter;
1371
1379
  const schedulerContext = {
1372
1380
  env: env as WorkerEnv["Bindings"],
1373
1381
  } as unknown as Context<WorkerEnv>;
@@ -1381,6 +1389,7 @@ export function createSchedulerExecutionContext(
1381
1389
  mutationEvents,
1382
1390
  user: null as never,
1383
1391
  session: null as never,
1392
+ auth: authAdapter,
1384
1393
  context: schedulerContext,
1385
1394
  scheduler: createScheduler(schedulerQueue),
1386
1395
  storage: null as never,
@@ -1414,6 +1423,14 @@ export async function createExecutionContext(
1414
1423
  const schedulerBinding = options.schedulerBinding ?? "APPFLARE_SCHEDULER_QUEUE";
1415
1424
  const schedulerQueue = c.env[schedulerBinding] as SchedulerQueueBinding | undefined;
1416
1425
  const helpers = createContextErrorHelpers();
1426
+ const auth = createAuth(
1427
+ {
1428
+ DATABASE: database,
1429
+ KV: kvNamespace,
1430
+ },
1431
+ c.req.raw.cf as IncomingRequestCfProperties | undefined,
1432
+ );
1433
+ const authAdapter = (await auth.$context).internalAdapter;
1417
1434
  const ctx = {
1418
1435
  $db: db,
1419
1436
  db: createQueryDb(db, {
@@ -1424,6 +1441,7 @@ export async function createExecutionContext(
1424
1441
  mutationEvents,
1425
1442
  user,
1426
1443
  session,
1444
+ auth: authAdapter,
1427
1445
  context: c,
1428
1446
  scheduler: createScheduler(schedulerQueue),
1429
1447
  storage: null as never,
@@ -4296,6 +4314,7 @@ type TableInsertModel<TName extends TableName> = InferInsertModel<
4296
4314
  `}function Ce(){return [qe(),$e(),Ie(),Ae(),Ne()].join(`
4297
4315
 
4298
4316
  `)}function Me(){return `type AuthSession = typeof auth.$Infer.Session;
4317
+ type AuthAdapter = Awaited<typeof auth.$context>["internalAdapter"];
4299
4318
  type User = AuthSession['user']
4300
4319
  type Session = AuthSession['session']
4301
4320
 
@@ -4351,6 +4370,7 @@ export type AppflareContext = {
4351
4370
  mutationEvents: DbMutationEvent[];
4352
4371
  user: User;
4353
4372
  session: Session;
4373
+ auth: AuthAdapter;
4354
4374
  context: Context<WorkerEnv>;
4355
4375
  scheduler: Scheduler;
4356
4376
  storage: AppflareStorage;
@@ -5787,7 +5807,7 @@ export async function executeScheduledBatch(
5787
5807
  return;
5788
5808
  }
5789
5809
 
5790
- const ctx = createSchedulerExecutionContext(env, options);
5810
+ const ctx = await createSchedulerExecutionContext(env, options);
5791
5811
 
5792
5812
  for (const message of batch.messages) {
5793
5813
  const body = (message?.body ?? {}) as QueueMessageBody;
@@ -5838,7 +5858,7 @@ export async function executeCronTriggers(
5838
5858
  return;
5839
5859
  }
5840
5860
 
5841
- const ctx = createSchedulerExecutionContext(env, options);
5861
+ const ctx = await createSchedulerExecutionContext(env, options);
5842
5862
 
5843
5863
  for (const cronEntry of cronHandlers) {
5844
5864
  if (!cronEntry.cronTriggers.includes(cronValue)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appflare",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",