appflare 0.0.28 → 0.1.1

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 (151) hide show
  1. package/cli/commands/index.ts +140 -0
  2. package/cli/generate.ts +149 -0
  3. package/cli/index.ts +56 -447
  4. package/cli/load-config.ts +182 -0
  5. package/cli/schema-compiler.ts +657 -0
  6. package/cli/templates/auth/README.md +156 -0
  7. package/cli/templates/auth/config.ts +61 -0
  8. package/cli/templates/auth/route-config.ts +18 -0
  9. package/cli/templates/auth/route-handler.ts +18 -0
  10. package/cli/templates/auth/route-request-utils.ts +55 -0
  11. package/cli/templates/auth/route.ts +14 -0
  12. package/cli/templates/core/README.md +266 -0
  13. package/cli/templates/core/app-creation.ts +19 -0
  14. package/cli/templates/core/client/appflare.ts +37 -0
  15. package/cli/templates/core/client/index.ts +6 -0
  16. package/cli/templates/core/client/storage.ts +100 -0
  17. package/cli/templates/core/client/types.ts +54 -0
  18. package/cli/templates/core/client-modules/appflare.ts +112 -0
  19. package/cli/templates/core/client-modules/handlers/index.ts +747 -0
  20. package/cli/templates/core/client-modules/handlers.ts +1 -0
  21. package/cli/templates/core/client-modules/index.ts +7 -0
  22. package/cli/templates/core/client-modules/storage.ts +180 -0
  23. package/cli/templates/core/client-modules/types.ts +145 -0
  24. package/cli/templates/core/client.ts +39 -0
  25. package/cli/templates/core/drizzle.ts +15 -0
  26. package/cli/templates/core/export.ts +14 -0
  27. package/cli/templates/core/handlers-route.ts +23 -0
  28. package/cli/templates/core/handlers.ts +1 -0
  29. package/cli/templates/core/imports.ts +8 -0
  30. package/cli/templates/core/server.ts +38 -0
  31. package/cli/templates/core/types.ts +6 -0
  32. package/cli/templates/core/wrangler.ts +109 -0
  33. package/cli/templates/handlers/README.md +353 -0
  34. package/cli/templates/handlers/auth.ts +37 -0
  35. package/cli/templates/handlers/execution.ts +39 -0
  36. package/cli/templates/handlers/generators/context/context-creation.ts +80 -0
  37. package/cli/templates/handlers/generators/context/error-helpers.ts +11 -0
  38. package/cli/templates/handlers/generators/context/scheduler.ts +24 -0
  39. package/cli/templates/handlers/generators/context/storage-api.ts +112 -0
  40. package/cli/templates/handlers/generators/context/storage-helpers.ts +59 -0
  41. package/cli/templates/handlers/generators/context/types.ts +18 -0
  42. package/cli/templates/handlers/generators/context.ts +43 -0
  43. package/cli/templates/handlers/generators/execution.ts +15 -0
  44. package/cli/templates/handlers/generators/handlers.ts +13 -0
  45. package/cli/templates/handlers/generators/registration/modules/cron.ts +30 -0
  46. package/cli/templates/handlers/generators/registration/modules/realtime.ts +631 -0
  47. package/cli/templates/handlers/generators/registration/modules/scheduler.ts +56 -0
  48. package/cli/templates/handlers/generators/registration/modules/storage.ts +194 -0
  49. package/cli/templates/handlers/generators/registration/sections.ts +210 -0
  50. package/cli/templates/handlers/generators/types/context.ts +64 -0
  51. package/cli/templates/handlers/generators/types/core.ts +101 -0
  52. package/cli/templates/handlers/generators/types/operations.ts +135 -0
  53. package/cli/templates/handlers/generators/types/query-definitions.ts +1029 -0
  54. package/cli/templates/handlers/generators/types/query-runtime.ts +417 -0
  55. package/cli/templates/handlers/index.ts +43 -0
  56. package/cli/templates/handlers/operations.ts +116 -0
  57. package/cli/templates/handlers/registration.ts +83 -0
  58. package/cli/templates/handlers/types.ts +15 -0
  59. package/cli/templates/handlers/utils.ts +48 -0
  60. package/cli/types.ts +108 -0
  61. package/cli/utils/handler-discovery.ts +366 -0
  62. package/cli/utils/json-utils.ts +24 -0
  63. package/cli/utils/path-utils.ts +19 -0
  64. package/cli/utils/schema-discovery.ts +390 -0
  65. package/index.ts +27 -4
  66. package/package.json +23 -20
  67. package/react/index.ts +5 -3
  68. package/react/use-infinite-query.ts +190 -0
  69. package/react/use-mutation.ts +54 -0
  70. package/react/use-query.ts +158 -0
  71. package/schema.ts +262 -0
  72. package/tsconfig.json +2 -4
  73. package/cli/README.md +0 -108
  74. package/cli/core/build.ts +0 -187
  75. package/cli/core/config.ts +0 -92
  76. package/cli/core/discover-handlers.ts +0 -143
  77. package/cli/core/handlers.ts +0 -7
  78. package/cli/core/index.ts +0 -205
  79. package/cli/generators/generate-api-client/client.ts +0 -163
  80. package/cli/generators/generate-api-client/extract-configuration.ts +0 -121
  81. package/cli/generators/generate-api-client/index.ts +0 -973
  82. package/cli/generators/generate-api-client/types.ts +0 -164
  83. package/cli/generators/generate-api-client/utils.ts +0 -22
  84. package/cli/generators/generate-api-client.ts +0 -1
  85. package/cli/generators/generate-cloudflare-worker/helpers.ts +0 -24
  86. package/cli/generators/generate-cloudflare-worker/index.ts +0 -2
  87. package/cli/generators/generate-cloudflare-worker/worker.ts +0 -148
  88. package/cli/generators/generate-cloudflare-worker/wrangler.ts +0 -108
  89. package/cli/generators/generate-cloudflare-worker.ts +0 -4
  90. package/cli/generators/generate-cron-handlers/cron-handlers-block.ts +0 -2
  91. package/cli/generators/generate-cron-handlers/handler-entries.ts +0 -29
  92. package/cli/generators/generate-cron-handlers/index.ts +0 -61
  93. package/cli/generators/generate-cron-handlers/runtime-block.ts +0 -49
  94. package/cli/generators/generate-cron-handlers/type-helpers-block.ts +0 -60
  95. package/cli/generators/generate-db-handlers/index.ts +0 -33
  96. package/cli/generators/generate-db-handlers/prepare.ts +0 -24
  97. package/cli/generators/generate-db-handlers/templates.ts +0 -189
  98. package/cli/generators/generate-db-handlers.ts +0 -1
  99. package/cli/generators/generate-hono-server/auth.ts +0 -97
  100. package/cli/generators/generate-hono-server/imports.ts +0 -55
  101. package/cli/generators/generate-hono-server/index.ts +0 -52
  102. package/cli/generators/generate-hono-server/routes.ts +0 -115
  103. package/cli/generators/generate-hono-server/template.ts +0 -371
  104. package/cli/generators/generate-hono-server.ts +0 -1
  105. package/cli/generators/generate-scheduler-handlers/constants.ts +0 -8
  106. package/cli/generators/generate-scheduler-handlers/handler-entries.ts +0 -22
  107. package/cli/generators/generate-scheduler-handlers/index.ts +0 -51
  108. package/cli/generators/generate-scheduler-handlers/runtime-block.ts +0 -68
  109. package/cli/generators/generate-scheduler-handlers/scheduler-handlers-block.ts +0 -2
  110. package/cli/generators/generate-scheduler-handlers/type-helpers-block.ts +0 -68
  111. package/cli/generators/generate-scheduler-handlers.ts +0 -1
  112. package/cli/generators/generate-websocket-durable-object/auth.ts +0 -30
  113. package/cli/generators/generate-websocket-durable-object/imports.ts +0 -55
  114. package/cli/generators/generate-websocket-durable-object/index.ts +0 -41
  115. package/cli/generators/generate-websocket-durable-object/query-handlers.ts +0 -18
  116. package/cli/generators/generate-websocket-durable-object/template.ts +0 -714
  117. package/cli/generators/generate-websocket-durable-object.ts +0 -1
  118. package/cli/schema/schema-static-types.ts +0 -702
  119. package/cli/schema/schema.ts +0 -151
  120. package/cli/utils/tsc.ts +0 -54
  121. package/cli/utils/utils.ts +0 -190
  122. package/cli/utils/zod-utils.ts +0 -121
  123. package/lib/README.md +0 -50
  124. package/lib/db.ts +0 -19
  125. package/lib/location.ts +0 -110
  126. package/lib/values.ts +0 -27
  127. package/react/README.md +0 -67
  128. package/react/hooks/useMutation.ts +0 -89
  129. package/react/hooks/usePaginatedQuery.ts +0 -213
  130. package/react/hooks/useQuery.ts +0 -106
  131. package/react/shared/queryShared.ts +0 -174
  132. package/server/README.md +0 -218
  133. package/server/auth.ts +0 -107
  134. package/server/database/builders.ts +0 -83
  135. package/server/database/context.ts +0 -327
  136. package/server/database/populate.ts +0 -234
  137. package/server/database/query-builder.ts +0 -161
  138. package/server/database/query-utils.ts +0 -25
  139. package/server/db.ts +0 -2
  140. package/server/storage/auth.ts +0 -16
  141. package/server/storage/bucket.ts +0 -22
  142. package/server/storage/context.ts +0 -34
  143. package/server/storage/index.ts +0 -38
  144. package/server/storage/operations.ts +0 -149
  145. package/server/storage/route-handler.ts +0 -60
  146. package/server/storage/types.ts +0 -55
  147. package/server/storage/utils.ts +0 -47
  148. package/server/storage.ts +0 -6
  149. package/server/types/schema-refs.ts +0 -66
  150. package/server/types/types.ts +0 -633
  151. package/server/utils/id-utils.ts +0 -230
@@ -1,230 +0,0 @@
1
- import type { Document, Filter } from "mongodb";
2
- import { ObjectId } from "mongodb";
3
- import type { Id, QueryWhere, SchemaRefMap } from "../types/types";
4
-
5
- export function isIdValue(value: unknown): value is string | ObjectId {
6
- return typeof value === "string" || value instanceof ObjectId;
7
- }
8
-
9
- function ensureObjectId(value: string | ObjectId): ObjectId {
10
- if (value instanceof ObjectId) return value;
11
- if (!ObjectId.isValid(value)) {
12
- throw new Error("Invalid id format; expected a 24-char hex ObjectId");
13
- }
14
- return new ObjectId(value);
15
- }
16
-
17
- const OPERATOR_ALIAS_MAP: Record<string, string> = {
18
- eq: "$eq",
19
- ne: "$ne",
20
- gt: "$gt",
21
- gte: "$gte",
22
- lt: "$lt",
23
- lte: "$lte",
24
- in: "$in",
25
- nin: "$nin",
26
- regex: "$regex",
27
- exists: "$exists",
28
- };
29
-
30
- const LOGICAL_ALIAS_MAP: Record<string, string> = {
31
- and: "$and",
32
- or: "$or",
33
- nor: "$nor",
34
- not: "$not",
35
- };
36
-
37
- type NormalizedRegex =
38
- | { $regex: string | RegExp; $options?: string }
39
- | RegExp
40
- | string;
41
-
42
- function normalizeRegexOperand(value: unknown): NormalizedRegex | undefined {
43
- if (value instanceof RegExp) return value;
44
- if (typeof value === "string") return value;
45
- if (value && typeof value === "object") {
46
- const obj = value as Record<string, unknown>;
47
- const pattern = obj.pattern ?? obj.regex ?? obj.$regex;
48
- const options = obj.options ?? obj.$options;
49
- if (pattern instanceof RegExp) return pattern;
50
- if (typeof pattern === "string") {
51
- const normalized: { $regex: string; $options?: string } = {
52
- $regex: pattern,
53
- };
54
- if (typeof options === "string" && options.length > 0) {
55
- normalized.$options = options;
56
- }
57
- return normalized;
58
- }
59
- }
60
- return undefined;
61
- }
62
-
63
- function normalizeWhereOperators(value: unknown): unknown {
64
- if (Array.isArray(value)) return value.map(normalizeWhereOperators);
65
- if (value instanceof RegExp || value instanceof Date) return value;
66
- if (value && typeof value === "object") {
67
- const obj = value as Record<string, unknown>;
68
- const out: Record<string, unknown> = {};
69
- for (const [key, val] of Object.entries(obj)) {
70
- const logicalKey = LOGICAL_ALIAS_MAP[key];
71
- if (logicalKey) {
72
- const normalizedLogical = Array.isArray(val)
73
- ? (val as unknown[]).map(normalizeWhereOperators)
74
- : normalizeWhereOperators(val);
75
- out[logicalKey] = normalizedLogical;
76
- continue;
77
- }
78
-
79
- if (key.startsWith("$")) {
80
- out[key] = normalizeWhereOperators(val);
81
- continue;
82
- }
83
-
84
- const opKey = OPERATOR_ALIAS_MAP[key];
85
- if (opKey) {
86
- if (opKey === "$regex") {
87
- const normalizedRegex = normalizeRegexOperand(val);
88
- if (normalizedRegex === undefined) continue;
89
- if (
90
- normalizedRegex &&
91
- typeof normalizedRegex === "object" &&
92
- !Array.isArray(normalizedRegex) &&
93
- !(normalizedRegex instanceof RegExp)
94
- ) {
95
- out.$regex = normalizedRegex.$regex;
96
- if (normalizedRegex.$options) {
97
- out.$options = normalizedRegex.$options;
98
- }
99
- } else {
100
- out[opKey] = normalizeWhereOperators(normalizedRegex);
101
- }
102
- continue;
103
- }
104
- out[opKey] = normalizeWhereOperators(val);
105
- continue;
106
- }
107
-
108
- out[key] = normalizeWhereOperators(val);
109
- }
110
- return out;
111
- }
112
- return value;
113
- }
114
-
115
- export function toMongoFilter(
116
- where: Id<any> | QueryWhere<any>
117
- ): Filter<Document> {
118
- if (isIdValue(where)) {
119
- return { _id: ensureObjectId(where) } satisfies Filter<Document> as any;
120
- }
121
- if (where && typeof where === "object") {
122
- const normalized = normalizeWhereOperators(where);
123
- return normalized as Filter<Document>;
124
- }
125
- throw new Error("update/delete requires an id or where filter object");
126
- }
127
-
128
- export function stringifyIdField(doc: Record<string, unknown>) {
129
- const id = doc._id;
130
- if (id instanceof ObjectId) {
131
- doc._id = id.toHexString();
132
- }
133
- }
134
-
135
- export function normalizeIdFilter(
136
- filter: Filter<Document> | undefined
137
- ): Filter<Document> | undefined {
138
- if (!filter) return filter;
139
- return normalizeIdFilterValue(filter) as Filter<Document>;
140
- }
141
-
142
- function normalizeIdFilterValue(value: unknown): unknown {
143
- if (Array.isArray(value)) return value.map(normalizeIdFilterValue);
144
- if (value && typeof value === "object") {
145
- const out: Record<string, unknown> = {};
146
- for (const [key, val] of Object.entries(value)) {
147
- if (key === "_id") {
148
- out[key] = normalizeIdValueForFilter(val);
149
- continue;
150
- }
151
- if (key === "$and" || key === "$or" || key === "$nor") {
152
- out[key] = Array.isArray(val)
153
- ? val.map(normalizeIdFilterValue)
154
- : normalizeIdFilterValue(val);
155
- continue;
156
- }
157
- out[key] = normalizeIdFilterValue(val);
158
- }
159
- return out;
160
- }
161
- return value;
162
- }
163
-
164
- function normalizeIdValueForFilter(value: unknown): unknown {
165
- if (Array.isArray(value)) return value.map(normalizeIdValueForFilter);
166
- if (value && typeof value === "object") {
167
- const out: Record<string, unknown> = {};
168
- for (const [key, val] of Object.entries(value)) {
169
- if (key === "$in" || key === "$nin" || key === "$all") {
170
- out[key] = Array.isArray(val)
171
- ? val.map(normalizeIdValue)
172
- : normalizeIdValue(val);
173
- continue;
174
- }
175
- out[key] = normalizeIdValueForFilter(val);
176
- }
177
- return out;
178
- }
179
- return normalizeIdValue(value);
180
- }
181
-
182
- export function normalizeIdValue(value: unknown): unknown {
183
- if (value instanceof ObjectId) return value;
184
- if (typeof value === "string" && ObjectId.isValid(value)) {
185
- return new ObjectId(value);
186
- }
187
- return value;
188
- }
189
-
190
- export function normalizeRefFields(
191
- table: string,
192
- value: Record<string, unknown>,
193
- refs: SchemaRefMap
194
- ): Record<string, unknown> {
195
- const tableRefs = refs.get(table);
196
- if (!tableRefs) return value;
197
-
198
- const out: Record<string, unknown> = { ...value };
199
- for (const key of tableRefs.keys()) {
200
- if (!(key in out)) continue;
201
- out[key] = normalizeRefFieldValue(out[key]);
202
- }
203
- return out;
204
- }
205
-
206
- function normalizeRefFieldValue(value: unknown): unknown {
207
- if (Array.isArray(value)) return value.map(normalizeRefFieldValue);
208
- return normalizeIdValue(value);
209
- }
210
-
211
- export function stringifyRefFields(
212
- table: string,
213
- doc: Record<string, unknown>,
214
- refs: SchemaRefMap
215
- ) {
216
- const tableRefs = refs.get(table);
217
- if (!tableRefs) return;
218
-
219
- for (const key of tableRefs.keys()) {
220
- const value = doc[key];
221
- if (value === undefined) continue;
222
- doc[key] = stringifyRefFieldValue(value);
223
- }
224
- }
225
-
226
- function stringifyRefFieldValue(value: unknown): unknown {
227
- if (value instanceof ObjectId) return value.toHexString();
228
- if (Array.isArray(value)) return value.map(stringifyRefFieldValue);
229
- return value;
230
- }