appflare 0.2.46 → 0.2.48

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.
Files changed (141) hide show
  1. package/Documentation.md +898 -898
  2. package/cli/commands/index.ts +247 -247
  3. package/cli/generate.ts +360 -360
  4. package/cli/index.ts +120 -120
  5. package/cli/load-config.ts +184 -184
  6. package/cli/schema-compiler.ts +1366 -1366
  7. package/cli/templates/auth/README.md +156 -156
  8. package/cli/templates/auth/config.ts +61 -61
  9. package/cli/templates/auth/route-config.ts +1 -1
  10. package/cli/templates/auth/route-handler.ts +1 -1
  11. package/cli/templates/auth/route-request-utils.ts +5 -5
  12. package/cli/templates/auth/route.config.ts +18 -18
  13. package/cli/templates/auth/route.handler.ts +18 -18
  14. package/cli/templates/auth/route.request-utils.ts +55 -55
  15. package/cli/templates/auth/route.ts +14 -14
  16. package/cli/templates/core/README.md +266 -266
  17. package/cli/templates/core/app-creation.ts +19 -19
  18. package/cli/templates/core/client/appflare.ts +112 -112
  19. package/cli/templates/core/client/handlers/index.ts +763 -763
  20. package/cli/templates/core/client/handlers.ts +1 -1
  21. package/cli/templates/core/client/index.ts +7 -7
  22. package/cli/templates/core/client/storage.ts +195 -195
  23. package/cli/templates/core/client/types.ts +187 -187
  24. package/cli/templates/core/client-modules/appflare.ts +1 -1
  25. package/cli/templates/core/client-modules/handlers.ts +1 -1
  26. package/cli/templates/core/client-modules/index.ts +1 -1
  27. package/cli/templates/core/client-modules/storage.ts +1 -1
  28. package/cli/templates/core/client-modules/types.ts +1 -1
  29. package/cli/templates/core/client.artifacts.ts +39 -39
  30. package/cli/templates/core/client.ts +4 -4
  31. package/cli/templates/core/drizzle.ts +15 -15
  32. package/cli/templates/core/export.ts +14 -14
  33. package/cli/templates/core/handlers.route.ts +24 -24
  34. package/cli/templates/core/handlers.ts +1 -1
  35. package/cli/templates/core/imports.ts +9 -9
  36. package/cli/templates/core/server.ts +38 -38
  37. package/cli/templates/core/types.ts +6 -6
  38. package/cli/templates/core/wrangler.ts +109 -109
  39. package/cli/templates/dashboard/builders/functions/index.ts +17 -17
  40. package/cli/templates/dashboard/builders/functions/render-page/header.ts +20 -20
  41. package/cli/templates/dashboard/builders/functions/render-page/index.ts +33 -33
  42. package/cli/templates/dashboard/builders/functions/render-page/request-panel.ts +271 -271
  43. package/cli/templates/dashboard/builders/functions/render-page/result-panel.ts +85 -85
  44. package/cli/templates/dashboard/builders/functions/render-page/scripts.ts +703 -703
  45. package/cli/templates/dashboard/builders/functions/tree-builder.ts +47 -47
  46. package/cli/templates/dashboard/builders/navigation.ts +155 -155
  47. package/cli/templates/dashboard/builders/storage/index.ts +13 -13
  48. package/cli/templates/dashboard/builders/storage/routes/create-directory-route.ts +29 -29
  49. package/cli/templates/dashboard/builders/storage/routes/delete-route.ts +18 -18
  50. package/cli/templates/dashboard/builders/storage/routes/download-route.ts +23 -23
  51. package/cli/templates/dashboard/builders/storage/routes/index.ts +22 -22
  52. package/cli/templates/dashboard/builders/storage/routes/list-route.ts +25 -25
  53. package/cli/templates/dashboard/builders/storage/routes/preview-route.ts +21 -21
  54. package/cli/templates/dashboard/builders/storage/routes/upload-route.ts +21 -21
  55. package/cli/templates/dashboard/builders/storage/runtime/helpers.ts +72 -72
  56. package/cli/templates/dashboard/builders/storage/runtime/storage-page.ts +130 -130
  57. package/cli/templates/dashboard/builders/table-routes/common/drawer-panel.ts +27 -27
  58. package/cli/templates/dashboard/builders/table-routes/common/pagination.ts +30 -30
  59. package/cli/templates/dashboard/builders/table-routes/common/search-bar.ts +23 -23
  60. package/cli/templates/dashboard/builders/table-routes/fragments.ts +217 -217
  61. package/cli/templates/dashboard/builders/table-routes/helpers.ts +45 -45
  62. package/cli/templates/dashboard/builders/table-routes/index.ts +8 -8
  63. package/cli/templates/dashboard/builders/table-routes/table/actions-cell.ts +71 -71
  64. package/cli/templates/dashboard/builders/table-routes/table/get-route.ts +291 -291
  65. package/cli/templates/dashboard/builders/table-routes/table/index.ts +80 -80
  66. package/cli/templates/dashboard/builders/table-routes/table/post-routes.ts +163 -163
  67. package/cli/templates/dashboard/builders/table-routes/table-route.ts +7 -7
  68. package/cli/templates/dashboard/builders/table-routes/users/get-route.ts +69 -69
  69. package/cli/templates/dashboard/builders/table-routes/users/html/modals.ts +57 -57
  70. package/cli/templates/dashboard/builders/table-routes/users/html/page.ts +27 -27
  71. package/cli/templates/dashboard/builders/table-routes/users/html/table.ts +128 -128
  72. package/cli/templates/dashboard/builders/table-routes/users/index.ts +32 -32
  73. package/cli/templates/dashboard/builders/table-routes/users/post-routes.ts +150 -150
  74. package/cli/templates/dashboard/builders/table-routes/users/redirect.ts +14 -14
  75. package/cli/templates/dashboard/builders/table-routes/users-route.ts +10 -10
  76. package/cli/templates/dashboard/components/dashboard-home.ts +23 -23
  77. package/cli/templates/dashboard/components/layout.ts +420 -420
  78. package/cli/templates/dashboard/components/login-page.ts +65 -65
  79. package/cli/templates/dashboard/index.ts +61 -61
  80. package/cli/templates/dashboard/types.ts +9 -9
  81. package/cli/templates/handlers/README.md +353 -353
  82. package/cli/templates/handlers/auth.ts +37 -37
  83. package/cli/templates/handlers/execution.ts +42 -42
  84. package/cli/templates/handlers/generators/context/context-creation.ts +101 -101
  85. package/cli/templates/handlers/generators/context/error-helpers.ts +11 -11
  86. package/cli/templates/handlers/generators/context/scheduler.ts +24 -24
  87. package/cli/templates/handlers/generators/context/storage-api.ts +82 -82
  88. package/cli/templates/handlers/generators/context/storage-helpers.ts +59 -59
  89. package/cli/templates/handlers/generators/context/types.ts +40 -40
  90. package/cli/templates/handlers/generators/context.ts +43 -43
  91. package/cli/templates/handlers/generators/execution.ts +15 -15
  92. package/cli/templates/handlers/generators/handlers.ts +14 -14
  93. package/cli/templates/handlers/generators/registration/modules/cron.ts +35 -26
  94. package/cli/templates/handlers/generators/registration/modules/realtime/auth.ts +75 -75
  95. package/cli/templates/handlers/generators/registration/modules/realtime/durable-object.ts +144 -144
  96. package/cli/templates/handlers/generators/registration/modules/realtime/index.ts +14 -14
  97. package/cli/templates/handlers/generators/registration/modules/realtime/publisher.ts +102 -102
  98. package/cli/templates/handlers/generators/registration/modules/realtime/routes.ts +164 -164
  99. package/cli/templates/handlers/generators/registration/modules/realtime/types.ts +30 -30
  100. package/cli/templates/handlers/generators/registration/modules/realtime/utils.ts +510 -510
  101. package/cli/templates/handlers/generators/registration/modules/scheduler.ts +65 -56
  102. package/cli/templates/handlers/generators/registration/modules/storage.ts +199 -199
  103. package/cli/templates/handlers/generators/registration/sections.ts +210 -210
  104. package/cli/templates/handlers/generators/types/context.ts +121 -121
  105. package/cli/templates/handlers/generators/types/core.ts +108 -106
  106. package/cli/templates/handlers/generators/types/operations.ts +135 -135
  107. package/cli/templates/handlers/generators/types/query-definitions/filter-and-where-types.ts +291 -291
  108. package/cli/templates/handlers/generators/types/query-definitions/query-api-types.ts +135 -135
  109. package/cli/templates/handlers/generators/types/query-definitions/query-helper-functions.ts +1382 -1382
  110. package/cli/templates/handlers/generators/types/query-definitions/schema-and-table-types.ts +278 -278
  111. package/cli/templates/handlers/generators/types/query-definitions.ts +13 -13
  112. package/cli/templates/handlers/generators/types/query-runtime/handled-error.ts +13 -13
  113. package/cli/templates/handlers/generators/types/query-runtime/runtime-aggregate-and-footer.ts +174 -174
  114. package/cli/templates/handlers/generators/types/query-runtime/runtime-read.ts +158 -157
  115. package/cli/templates/handlers/generators/types/query-runtime/runtime-setup.ts +45 -45
  116. package/cli/templates/handlers/generators/types/query-runtime/runtime-write.ts +958 -958
  117. package/cli/templates/handlers/generators/types/query-runtime.ts +15 -15
  118. package/cli/templates/handlers/index.ts +47 -47
  119. package/cli/templates/handlers/operations.ts +116 -116
  120. package/cli/templates/handlers/registration.ts +91 -91
  121. package/cli/templates/handlers/types.ts +17 -17
  122. package/cli/templates/handlers/utils.ts +48 -48
  123. package/cli/types.ts +110 -110
  124. package/cli/utils/handler-discovery.ts +501 -501
  125. package/cli/utils/json-utils.ts +24 -24
  126. package/cli/utils/path-utils.ts +19 -19
  127. package/cli/utils/schema-discovery.ts +399 -399
  128. package/dist/cli/index.js +43 -23
  129. package/dist/cli/index.mjs +43 -23
  130. package/dist/react/index.js +1 -1
  131. package/dist/react/index.mjs +1 -1
  132. package/index.ts +18 -18
  133. package/package.json +58 -58
  134. package/react/index.ts +5 -5
  135. package/react/use-infinite-query.ts +255 -255
  136. package/react/use-mutation.ts +89 -89
  137. package/react/use-query.ts +210 -210
  138. package/schema.ts +641 -641
  139. package/test-better-auth-hash.ts +2 -2
  140. package/tsconfig.json +6 -6
  141. package/tsup.config.ts +82 -82
@@ -1,15 +1,15 @@
1
- import { generateQueryRuntimeAggregateAndFooterSection } from "./query-runtime/runtime-aggregate-and-footer";
2
- import { generateQueryRuntimeHandledErrorSection } from "./query-runtime/handled-error";
3
- import { generateQueryRuntimeReadSection } from "./query-runtime/runtime-read";
4
- import { generateQueryRuntimeSetupSection } from "./query-runtime/runtime-setup";
5
- import { generateQueryRuntimeWriteSection } from "./query-runtime/runtime-write";
6
-
7
- export function generateTypesQueryRuntimeSection(): string {
8
- return [
9
- generateQueryRuntimeSetupSection(),
10
- generateQueryRuntimeReadSection(),
11
- generateQueryRuntimeWriteSection(),
12
- generateQueryRuntimeAggregateAndFooterSection(),
13
- generateQueryRuntimeHandledErrorSection(),
14
- ].join("\n\n");
15
- }
1
+ import { generateQueryRuntimeAggregateAndFooterSection } from "./query-runtime/runtime-aggregate-and-footer";
2
+ import { generateQueryRuntimeHandledErrorSection } from "./query-runtime/handled-error";
3
+ import { generateQueryRuntimeReadSection } from "./query-runtime/runtime-read";
4
+ import { generateQueryRuntimeSetupSection } from "./query-runtime/runtime-setup";
5
+ import { generateQueryRuntimeWriteSection } from "./query-runtime/runtime-write";
6
+
7
+ export function generateTypesQueryRuntimeSection(): string {
8
+ return [
9
+ generateQueryRuntimeSetupSection(),
10
+ generateQueryRuntimeReadSection(),
11
+ generateQueryRuntimeWriteSection(),
12
+ generateQueryRuntimeAggregateAndFooterSection(),
13
+ generateQueryRuntimeHandledErrorSection(),
14
+ ].join("\n\n");
15
+ }
@@ -1,47 +1,47 @@
1
- import { DiscoveredHandlerOperation } from "../../utils/handler-discovery";
2
- import { generateContextSource } from "./generators/context";
3
- import { generateExecutionSource } from "./generators/execution";
4
- import { generateHandlersSource } from "./generators/handlers";
5
- import { generateRegistration } from "./registration";
6
-
7
- export type AdditionalField = { name: string; tsType: string };
8
-
9
- export type GeneratedHandlerArtifact = {
10
- relativePath: string;
11
- source: string;
12
- };
13
-
14
- export function generateHandlersArtifacts(
15
- schemaImportPath: string,
16
- operations: DiscoveredHandlerOperation[],
17
- defaultR2Binding?: string,
18
- roles: string[] = [],
19
- additionalFields: AdditionalField[] = [],
20
- ): GeneratedHandlerArtifact[] {
21
- const handlersSource = generateHandlersSource(schemaImportPath, roles, additionalFields);
22
-
23
- const contextSource = generateContextSource(defaultR2Binding);
24
-
25
- const executionSource = generateExecutionSource();
26
-
27
- const routesSource = generateRegistration(operations);
28
-
29
- return [
30
- {
31
- relativePath: "handlers.ts",
32
- source: handlersSource,
33
- },
34
- {
35
- relativePath: "handlers.context.ts",
36
- source: contextSource,
37
- },
38
- {
39
- relativePath: "handlers.execution.ts",
40
- source: executionSource,
41
- },
42
- {
43
- relativePath: "handlers.routes.ts",
44
- source: routesSource,
45
- },
46
- ];
47
- }
1
+ import { DiscoveredHandlerOperation } from "../../utils/handler-discovery";
2
+ import { generateContextSource } from "./generators/context";
3
+ import { generateExecutionSource } from "./generators/execution";
4
+ import { generateHandlersSource } from "./generators/handlers";
5
+ import { generateRegistration } from "./registration";
6
+
7
+ export type AdditionalField = { name: string; tsType: string };
8
+
9
+ export type GeneratedHandlerArtifact = {
10
+ relativePath: string;
11
+ source: string;
12
+ };
13
+
14
+ export function generateHandlersArtifacts(
15
+ schemaImportPath: string,
16
+ operations: DiscoveredHandlerOperation[],
17
+ defaultR2Binding?: string,
18
+ roles: string[] = [],
19
+ additionalFields: AdditionalField[] = [],
20
+ ): GeneratedHandlerArtifact[] {
21
+ const handlersSource = generateHandlersSource(schemaImportPath, roles, additionalFields);
22
+
23
+ const contextSource = generateContextSource(defaultR2Binding);
24
+
25
+ const executionSource = generateExecutionSource();
26
+
27
+ const routesSource = generateRegistration(operations);
28
+
29
+ return [
30
+ {
31
+ relativePath: "handlers.ts",
32
+ source: handlersSource,
33
+ },
34
+ {
35
+ relativePath: "handlers.context.ts",
36
+ source: contextSource,
37
+ },
38
+ {
39
+ relativePath: "handlers.execution.ts",
40
+ source: executionSource,
41
+ },
42
+ {
43
+ relativePath: "handlers.routes.ts",
44
+ source: routesSource,
45
+ },
46
+ ];
47
+ }
@@ -1,116 +1,116 @@
1
- import {
2
- toPascalCase,
3
- singularize,
4
- zodForColumn,
5
- zodForQueryColumn,
6
- } from "./utils";
7
- import type {
8
- DiscoveredColumn,
9
- DiscoveredTable,
10
- } from "../../utils/schema-discovery";
11
-
12
- function createArgsShape(columns: DiscoveredColumn[]): string {
13
- const creatableColumns = columns.filter(
14
- (column) => !(column.primaryKey && column.autoIncrement),
15
- );
16
- if (creatableColumns.length === 0) {
17
- return "{}";
18
- }
19
-
20
- return `{
21
- ${creatableColumns.map((column) => `\t\t${column.name}: ${zodForColumn(column)},`).join("\n")}
22
- \t}`;
23
- }
24
-
25
- function createInsertValues(columns: DiscoveredColumn[]): string {
26
- const creatableColumns = columns.filter(
27
- (column) => !(column.primaryKey && column.autoIncrement),
28
- );
29
-
30
- if (creatableColumns.length === 0) {
31
- return "{}";
32
- }
33
-
34
- return `{
35
- ${creatableColumns.map((column) => `\t\t\t${column.name}: args.${column.name},`).join("\n")}
36
- \t\t}`;
37
- }
38
-
39
- function createQueryBlock(table: DiscoveredTable): string {
40
- const idColumn = table.columns.find((column) => column.name === "id");
41
- const queryName = `get${toPascalCase(table.exportName)}`;
42
- const args = idColumn
43
- ? `{
44
- id: ${zodForQueryColumn(idColumn)},
45
- \t}`
46
- : "{}";
47
- const queryBody = idColumn
48
- ? `if (args.id !== undefined) {
49
- return ctx.$db.select().from(schema.${table.exportName}).where(eq(schema.${table.exportName}.id, args.id));
50
- \t\t}
51
- \n\t\treturn ctx.$db.select().from(schema.${table.exportName});`
52
- : `return ctx.$db.select().from(schema.${table.exportName});`;
53
-
54
- return `export const ${queryName} = query({
55
- \targs: ${args},
56
- \thandler: async (ctx, args) => {
57
- \t\t${queryBody}
58
- \t},
59
- });`;
60
- }
61
-
62
- function createMutationBlock(table: DiscoveredTable): string {
63
- const mutationName = `create${toPascalCase(singularize(table.exportName))}`;
64
- const argsShape = createArgsShape(table.columns);
65
- const values = createInsertValues(table.columns);
66
-
67
- return `export const ${mutationName} = mutation({
68
- \targs: ${argsShape},
69
- \thandler: async (ctx, args) => {
70
- const [created] = await ctx.$db
71
- \t\t\t.insert(schema.${table.exportName})
72
- \t\t\t.values(${values})
73
- \t\t\t.returning();
74
-
75
- \n\t\treturn created ?? null;
76
- \t},
77
- });`;
78
- }
79
-
80
- function createRegistry(tableNames: string[]): string {
81
- const queryEntries = tableNames.map((name) => {
82
- return `\t${`get${toPascalCase(name)}`},`;
83
- });
84
- const mutationEntries = tableNames.map((name) => {
85
- return `\t${`create${toPascalCase(singularize(name))}`},`;
86
- });
87
-
88
- return `const generatedQueries = {
89
- ${queryEntries.join("\n")}
90
- } as const;
91
-
92
- const generatedMutations = {
93
- ${mutationEntries.join("\n")}
94
- } as const;`;
95
- }
96
-
97
- export function generateOperations(tables: DiscoveredTable[]): string {
98
- if (tables.length === 0) {
99
- return `const generatedQueries = {} as const;
100
- const generatedMutations = {} as const;`;
101
- }
102
-
103
- const queryBlocks = tables
104
- .map((table) => createQueryBlock(table))
105
- .join("\n\n");
106
- const mutationBlocks = tables
107
- .map((table) => createMutationBlock(table))
108
- .join("\n\n");
109
- const registry = createRegistry(tables.map((table) => table.exportName));
110
-
111
- return `${queryBlocks}
112
-
113
- ${mutationBlocks}
114
-
115
- ${registry}`;
116
- }
1
+ import {
2
+ toPascalCase,
3
+ singularize,
4
+ zodForColumn,
5
+ zodForQueryColumn,
6
+ } from "./utils";
7
+ import type {
8
+ DiscoveredColumn,
9
+ DiscoveredTable,
10
+ } from "../../utils/schema-discovery";
11
+
12
+ function createArgsShape(columns: DiscoveredColumn[]): string {
13
+ const creatableColumns = columns.filter(
14
+ (column) => !(column.primaryKey && column.autoIncrement),
15
+ );
16
+ if (creatableColumns.length === 0) {
17
+ return "{}";
18
+ }
19
+
20
+ return `{
21
+ ${creatableColumns.map((column) => `\t\t${column.name}: ${zodForColumn(column)},`).join("\n")}
22
+ \t}`;
23
+ }
24
+
25
+ function createInsertValues(columns: DiscoveredColumn[]): string {
26
+ const creatableColumns = columns.filter(
27
+ (column) => !(column.primaryKey && column.autoIncrement),
28
+ );
29
+
30
+ if (creatableColumns.length === 0) {
31
+ return "{}";
32
+ }
33
+
34
+ return `{
35
+ ${creatableColumns.map((column) => `\t\t\t${column.name}: args.${column.name},`).join("\n")}
36
+ \t\t}`;
37
+ }
38
+
39
+ function createQueryBlock(table: DiscoveredTable): string {
40
+ const idColumn = table.columns.find((column) => column.name === "id");
41
+ const queryName = `get${toPascalCase(table.exportName)}`;
42
+ const args = idColumn
43
+ ? `{
44
+ id: ${zodForQueryColumn(idColumn)},
45
+ \t}`
46
+ : "{}";
47
+ const queryBody = idColumn
48
+ ? `if (args.id !== undefined) {
49
+ return ctx.$db.select().from(schema.${table.exportName}).where(eq(schema.${table.exportName}.id, args.id));
50
+ \t\t}
51
+ \n\t\treturn ctx.$db.select().from(schema.${table.exportName});`
52
+ : `return ctx.$db.select().from(schema.${table.exportName});`;
53
+
54
+ return `export const ${queryName} = query({
55
+ \targs: ${args},
56
+ \thandler: async (ctx, args) => {
57
+ \t\t${queryBody}
58
+ \t},
59
+ });`;
60
+ }
61
+
62
+ function createMutationBlock(table: DiscoveredTable): string {
63
+ const mutationName = `create${toPascalCase(singularize(table.exportName))}`;
64
+ const argsShape = createArgsShape(table.columns);
65
+ const values = createInsertValues(table.columns);
66
+
67
+ return `export const ${mutationName} = mutation({
68
+ \targs: ${argsShape},
69
+ \thandler: async (ctx, args) => {
70
+ const [created] = await ctx.$db
71
+ \t\t\t.insert(schema.${table.exportName})
72
+ \t\t\t.values(${values})
73
+ \t\t\t.returning();
74
+
75
+ \n\t\treturn created ?? null;
76
+ \t},
77
+ });`;
78
+ }
79
+
80
+ function createRegistry(tableNames: string[]): string {
81
+ const queryEntries = tableNames.map((name) => {
82
+ return `\t${`get${toPascalCase(name)}`},`;
83
+ });
84
+ const mutationEntries = tableNames.map((name) => {
85
+ return `\t${`create${toPascalCase(singularize(name))}`},`;
86
+ });
87
+
88
+ return `const generatedQueries = {
89
+ ${queryEntries.join("\n")}
90
+ } as const;
91
+
92
+ const generatedMutations = {
93
+ ${mutationEntries.join("\n")}
94
+ } as const;`;
95
+ }
96
+
97
+ export function generateOperations(tables: DiscoveredTable[]): string {
98
+ if (tables.length === 0) {
99
+ return `const generatedQueries = {} as const;
100
+ const generatedMutations = {} as const;`;
101
+ }
102
+
103
+ const queryBlocks = tables
104
+ .map((table) => createQueryBlock(table))
105
+ .join("\n\n");
106
+ const mutationBlocks = tables
107
+ .map((table) => createMutationBlock(table))
108
+ .join("\n\n");
109
+ const registry = createRegistry(tables.map((table) => table.exportName));
110
+
111
+ return `${queryBlocks}
112
+
113
+ ${mutationBlocks}
114
+
115
+ ${registry}`;
116
+ }
@@ -1,91 +1,91 @@
1
- import type { DiscoveredHandlerOperation } from "../../utils/handler-discovery";
2
- import { buildRegistrationTemplateSections } from "./generators/registration/sections";
3
- import { realtimeModule } from "./generators/registration/modules/realtime";
4
- import { storageModule } from "./generators/registration/modules/storage";
5
- import { schedulerModule } from "./generators/registration/modules/scheduler";
6
- import { cronModule } from "./generators/registration/modules/cron";
7
-
8
- export function generateRegistration(
9
- operations: DiscoveredHandlerOperation[],
10
- ): string {
11
- const {
12
- imports,
13
- operationSchemas,
14
- schedulerSchemas,
15
- queryRoutes,
16
- mutationRoutes,
17
- queryRegistryEntries,
18
- schedulerEntries,
19
- schedulerPayloadMapEntries,
20
- cronEntries,
21
- storageHandlersEntries,
22
- } = buildRegistrationTemplateSections(operations);
23
-
24
- return `import { sValidator } from "@hono/standard-validator";
25
- import type { Hono } from "hono";
26
- import type { D1Database, IncomingRequestCfProperties, KVNamespace } from "@cloudflare/workers-types";
27
- import { ZodError, z } from "zod";
28
- import {
29
- AppflareHandledError,
30
- type AppflareContext,
31
- type DbMutationEvent,
32
- createDb,
33
- createQueryDb,
34
- setStorageHandlers,
35
- type RegisterHandlersOptions,
36
- type StorageMethod,
37
- type WorkerEnv,
38
- } from "./handlers";
39
- import { createExecutionContext, createSchedulerExecutionContext, resolveSession } from "./handlers.context";
40
- import { executeOperation, handleOperationError } from "./handlers.execution";
41
- ${imports ? `\n${imports}` : ""}
42
-
43
- ${operationSchemas}
44
- ${schedulerSchemas}
45
-
46
- const realtimeQueryHandlers = {${queryRegistryEntries || "\n"}
47
- } as const;
48
-
49
- const schedulerHandlers = {${schedulerEntries || "\n"}
50
- } as const;
51
-
52
- type GeneratedSchedulerPayloadMap = {${
53
- schedulerPayloadMapEntries ? `\n${schedulerPayloadMapEntries}\n` : ""
54
- }};
55
-
56
- declare global {
57
- interface AppflareSchedulerHandlerMap extends GeneratedSchedulerPayloadMap {}
58
- }
59
-
60
- type CronHandlerEntry = {
61
- taskName: string;
62
- cronTriggers: readonly string[];
63
- definition: {
64
- handler: (ctx: AppflareContext) => void | Promise<void>;
65
- };
66
- };
67
-
68
- const cronHandlers: readonly CronHandlerEntry[] = [${cronEntries || "\n"}
69
- ];
70
-
71
- const storageHandlers = [${storageHandlersEntries || "\n"}
72
- ] as const;
73
-
74
- setStorageHandlers([...storageHandlers]);
75
-
76
- ${schedulerModule}
77
-
78
- ${realtimeModule}
79
-
80
- export function registerGeneratedHandlers(
81
- app: Hono<WorkerEnv>,
82
- options: RegisterHandlersOptions,
83
- ): void {
84
- registerRealtimeRoutes(app, options);${queryRoutes || "\n\t// No query handlers discovered under scanDir/queries.\n"}${mutationRoutes || "\n\t// No mutation handlers discovered under scanDir/mutations.\n"}
85
- }
86
-
87
- ${storageModule}
88
-
89
- ${cronModule}
90
- `;
91
- }
1
+ import type { DiscoveredHandlerOperation } from "../../utils/handler-discovery";
2
+ import { buildRegistrationTemplateSections } from "./generators/registration/sections";
3
+ import { realtimeModule } from "./generators/registration/modules/realtime";
4
+ import { storageModule } from "./generators/registration/modules/storage";
5
+ import { schedulerModule } from "./generators/registration/modules/scheduler";
6
+ import { cronModule } from "./generators/registration/modules/cron";
7
+
8
+ export function generateRegistration(
9
+ operations: DiscoveredHandlerOperation[],
10
+ ): string {
11
+ const {
12
+ imports,
13
+ operationSchemas,
14
+ schedulerSchemas,
15
+ queryRoutes,
16
+ mutationRoutes,
17
+ queryRegistryEntries,
18
+ schedulerEntries,
19
+ schedulerPayloadMapEntries,
20
+ cronEntries,
21
+ storageHandlersEntries,
22
+ } = buildRegistrationTemplateSections(operations);
23
+
24
+ return `import { sValidator } from "@hono/standard-validator";
25
+ import type { Hono } from "hono";
26
+ import type { D1Database, IncomingRequestCfProperties, KVNamespace } from "@cloudflare/workers-types";
27
+ import { ZodError, z } from "zod";
28
+ import {
29
+ AppflareHandledError,
30
+ type AppflareContext,
31
+ type DbMutationEvent,
32
+ createDb,
33
+ createQueryDb,
34
+ setStorageHandlers,
35
+ type RegisterHandlersOptions,
36
+ type StorageMethod,
37
+ type WorkerEnv,
38
+ } from "./handlers";
39
+ import { createExecutionContext, createSchedulerExecutionContext, resolveSession } from "./handlers.context";
40
+ import { executeOperation, handleOperationError } from "./handlers.execution";
41
+ ${imports ? `\n${imports}` : ""}
42
+
43
+ ${operationSchemas}
44
+ ${schedulerSchemas}
45
+
46
+ const realtimeQueryHandlers = {${queryRegistryEntries || "\n"}
47
+ } as const;
48
+
49
+ const schedulerHandlers = {${schedulerEntries || "\n"}
50
+ } as const;
51
+
52
+ type GeneratedSchedulerPayloadMap = {${
53
+ schedulerPayloadMapEntries ? `\n${schedulerPayloadMapEntries}\n` : ""
54
+ }};
55
+
56
+ declare global {
57
+ interface AppflareSchedulerHandlerMap extends GeneratedSchedulerPayloadMap {}
58
+ }
59
+
60
+ type CronHandlerEntry = {
61
+ taskName: string;
62
+ cronTriggers: readonly string[];
63
+ definition: {
64
+ handler: (ctx: AppflareContext) => void | Promise<void>;
65
+ };
66
+ };
67
+
68
+ const cronHandlers: readonly CronHandlerEntry[] = [${cronEntries || "\n"}
69
+ ];
70
+
71
+ const storageHandlers = [${storageHandlersEntries || "\n"}
72
+ ] as const;
73
+
74
+ setStorageHandlers([...storageHandlers]);
75
+
76
+ ${schedulerModule}
77
+
78
+ ${realtimeModule}
79
+
80
+ export function registerGeneratedHandlers(
81
+ app: Hono<WorkerEnv>,
82
+ options: RegisterHandlersOptions,
83
+ ): void {
84
+ registerRealtimeRoutes(app, options);${queryRoutes || "\n\t// No query handlers discovered under scanDir/queries.\n"}${mutationRoutes || "\n\t// No mutation handlers discovered under scanDir/mutations.\n"}
85
+ }
86
+
87
+ ${storageModule}
88
+
89
+ ${cronModule}
90
+ `;
91
+ }
@@ -1,17 +1,17 @@
1
- import { generateTypesCoreSection } from "./generators/types/core";
2
- import { generateTypesQueryDefinitionsSection } from "./generators/types/query-definitions";
3
- import { generateTypesQueryRuntimeSection } from "./generators/types/query-runtime";
4
- import { generateTypesContextSection } from "./generators/types/context";
5
- import { generateTypesOperationsSection } from "./generators/types/operations";
6
-
7
- export type AdditionalField = { name: string; tsType: string };
8
-
9
- export function generateTypes(roles: string[] = [], additionalFields: AdditionalField[] = []): string {
10
- return [
11
- generateTypesCoreSection(),
12
- generateTypesQueryDefinitionsSection(),
13
- generateTypesQueryRuntimeSection(),
14
- generateTypesContextSection(roles, additionalFields),
15
- generateTypesOperationsSection(),
16
- ].join("\n\n");
17
- }
1
+ import { generateTypesCoreSection } from "./generators/types/core";
2
+ import { generateTypesQueryDefinitionsSection } from "./generators/types/query-definitions";
3
+ import { generateTypesQueryRuntimeSection } from "./generators/types/query-runtime";
4
+ import { generateTypesContextSection } from "./generators/types/context";
5
+ import { generateTypesOperationsSection } from "./generators/types/operations";
6
+
7
+ export type AdditionalField = { name: string; tsType: string };
8
+
9
+ export function generateTypes(roles: string[] = [], additionalFields: AdditionalField[] = []): string {
10
+ return [
11
+ generateTypesCoreSection(),
12
+ generateTypesQueryDefinitionsSection(),
13
+ generateTypesQueryRuntimeSection(),
14
+ generateTypesContextSection(roles, additionalFields),
15
+ generateTypesOperationsSection(),
16
+ ].join("\n\n");
17
+ }
@@ -1,48 +1,48 @@
1
- import type { DiscoveredColumn } from "../../utils/schema-discovery";
2
-
3
- export function toPascalCase(value: string): string {
4
- return value
5
- .replace(/[_-]+/g, " ")
6
- .replace(/\s+(.)/g, (_match, char: string) => char.toUpperCase())
7
- .replace(/\s/g, "")
8
- .replace(/^(.)/, (_match, char: string) => char.toUpperCase());
9
- }
10
-
11
- export function singularize(value: string): string {
12
- if (value.endsWith("ies")) {
13
- return `${value.slice(0, -3)}y`;
14
- }
15
- if (value.endsWith("ses")) {
16
- return value.slice(0, -2);
17
- }
18
- if (value.endsWith("s") && value.length > 1) {
19
- return value.slice(0, -1);
20
- }
21
- return value;
22
- }
23
-
24
- export function zodForColumn(column: DiscoveredColumn): string {
25
- if (column.type === "number") {
26
- return `z.number()${column.optional ? ".optional()" : ""}`;
27
- }
28
- if (column.type === "boolean") {
29
- return `z.boolean()${column.optional ? ".optional()" : ""}`;
30
- }
31
- if (column.type === "string") {
32
- return `z.string()${column.optional ? ".optional()" : ""}`;
33
- }
34
- return `z.unknown()${column.optional ? ".optional()" : ""}`;
35
- }
36
-
37
- export function zodForQueryColumn(column: DiscoveredColumn): string {
38
- if (column.type === "number") {
39
- return "z.coerce.number().optional()";
40
- }
41
- if (column.type === "boolean") {
42
- return "z.coerce.boolean().optional()";
43
- }
44
- if (column.type === "string") {
45
- return "z.string().optional()";
46
- }
47
- return "z.unknown().optional()";
48
- }
1
+ import type { DiscoveredColumn } from "../../utils/schema-discovery";
2
+
3
+ export function toPascalCase(value: string): string {
4
+ return value
5
+ .replace(/[_-]+/g, " ")
6
+ .replace(/\s+(.)/g, (_match, char: string) => char.toUpperCase())
7
+ .replace(/\s/g, "")
8
+ .replace(/^(.)/, (_match, char: string) => char.toUpperCase());
9
+ }
10
+
11
+ export function singularize(value: string): string {
12
+ if (value.endsWith("ies")) {
13
+ return `${value.slice(0, -3)}y`;
14
+ }
15
+ if (value.endsWith("ses")) {
16
+ return value.slice(0, -2);
17
+ }
18
+ if (value.endsWith("s") && value.length > 1) {
19
+ return value.slice(0, -1);
20
+ }
21
+ return value;
22
+ }
23
+
24
+ export function zodForColumn(column: DiscoveredColumn): string {
25
+ if (column.type === "number") {
26
+ return `z.number()${column.optional ? ".optional()" : ""}`;
27
+ }
28
+ if (column.type === "boolean") {
29
+ return `z.boolean()${column.optional ? ".optional()" : ""}`;
30
+ }
31
+ if (column.type === "string") {
32
+ return `z.string()${column.optional ? ".optional()" : ""}`;
33
+ }
34
+ return `z.unknown()${column.optional ? ".optional()" : ""}`;
35
+ }
36
+
37
+ export function zodForQueryColumn(column: DiscoveredColumn): string {
38
+ if (column.type === "number") {
39
+ return "z.coerce.number().optional()";
40
+ }
41
+ if (column.type === "boolean") {
42
+ return "z.coerce.boolean().optional()";
43
+ }
44
+ if (column.type === "string") {
45
+ return "z.string().optional()";
46
+ }
47
+ return "z.unknown().optional()";
48
+ }