appflare 0.0.28 → 0.1.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.
Files changed (141) 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 +740 -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 +265 -0
  34. package/cli/templates/handlers/auth.ts +36 -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/index.ts +43 -0
  46. package/cli/templates/handlers/operations.ts +116 -0
  47. package/cli/templates/handlers/registration.ts +1114 -0
  48. package/cli/templates/handlers/types.ts +960 -0
  49. package/cli/templates/handlers/utils.ts +48 -0
  50. package/cli/types.ts +108 -0
  51. package/cli/utils/handler-discovery.ts +366 -0
  52. package/cli/utils/json-utils.ts +24 -0
  53. package/cli/utils/path-utils.ts +19 -0
  54. package/cli/utils/schema-discovery.ts +390 -0
  55. package/index.ts +27 -4
  56. package/package.json +23 -20
  57. package/react/index.ts +5 -3
  58. package/react/use-infinite-query.ts +190 -0
  59. package/react/use-mutation.ts +54 -0
  60. package/react/use-query.ts +158 -0
  61. package/schema.ts +262 -0
  62. package/tsconfig.json +2 -4
  63. package/cli/README.md +0 -108
  64. package/cli/core/build.ts +0 -187
  65. package/cli/core/config.ts +0 -92
  66. package/cli/core/discover-handlers.ts +0 -143
  67. package/cli/core/handlers.ts +0 -7
  68. package/cli/core/index.ts +0 -205
  69. package/cli/generators/generate-api-client/client.ts +0 -163
  70. package/cli/generators/generate-api-client/extract-configuration.ts +0 -121
  71. package/cli/generators/generate-api-client/index.ts +0 -973
  72. package/cli/generators/generate-api-client/types.ts +0 -164
  73. package/cli/generators/generate-api-client/utils.ts +0 -22
  74. package/cli/generators/generate-api-client.ts +0 -1
  75. package/cli/generators/generate-cloudflare-worker/helpers.ts +0 -24
  76. package/cli/generators/generate-cloudflare-worker/index.ts +0 -2
  77. package/cli/generators/generate-cloudflare-worker/worker.ts +0 -148
  78. package/cli/generators/generate-cloudflare-worker/wrangler.ts +0 -108
  79. package/cli/generators/generate-cloudflare-worker.ts +0 -4
  80. package/cli/generators/generate-cron-handlers/cron-handlers-block.ts +0 -2
  81. package/cli/generators/generate-cron-handlers/handler-entries.ts +0 -29
  82. package/cli/generators/generate-cron-handlers/index.ts +0 -61
  83. package/cli/generators/generate-cron-handlers/runtime-block.ts +0 -49
  84. package/cli/generators/generate-cron-handlers/type-helpers-block.ts +0 -60
  85. package/cli/generators/generate-db-handlers/index.ts +0 -33
  86. package/cli/generators/generate-db-handlers/prepare.ts +0 -24
  87. package/cli/generators/generate-db-handlers/templates.ts +0 -189
  88. package/cli/generators/generate-db-handlers.ts +0 -1
  89. package/cli/generators/generate-hono-server/auth.ts +0 -97
  90. package/cli/generators/generate-hono-server/imports.ts +0 -55
  91. package/cli/generators/generate-hono-server/index.ts +0 -52
  92. package/cli/generators/generate-hono-server/routes.ts +0 -115
  93. package/cli/generators/generate-hono-server/template.ts +0 -371
  94. package/cli/generators/generate-hono-server.ts +0 -1
  95. package/cli/generators/generate-scheduler-handlers/constants.ts +0 -8
  96. package/cli/generators/generate-scheduler-handlers/handler-entries.ts +0 -22
  97. package/cli/generators/generate-scheduler-handlers/index.ts +0 -51
  98. package/cli/generators/generate-scheduler-handlers/runtime-block.ts +0 -68
  99. package/cli/generators/generate-scheduler-handlers/scheduler-handlers-block.ts +0 -2
  100. package/cli/generators/generate-scheduler-handlers/type-helpers-block.ts +0 -68
  101. package/cli/generators/generate-scheduler-handlers.ts +0 -1
  102. package/cli/generators/generate-websocket-durable-object/auth.ts +0 -30
  103. package/cli/generators/generate-websocket-durable-object/imports.ts +0 -55
  104. package/cli/generators/generate-websocket-durable-object/index.ts +0 -41
  105. package/cli/generators/generate-websocket-durable-object/query-handlers.ts +0 -18
  106. package/cli/generators/generate-websocket-durable-object/template.ts +0 -714
  107. package/cli/generators/generate-websocket-durable-object.ts +0 -1
  108. package/cli/schema/schema-static-types.ts +0 -702
  109. package/cli/schema/schema.ts +0 -151
  110. package/cli/utils/tsc.ts +0 -54
  111. package/cli/utils/utils.ts +0 -190
  112. package/cli/utils/zod-utils.ts +0 -121
  113. package/lib/README.md +0 -50
  114. package/lib/db.ts +0 -19
  115. package/lib/location.ts +0 -110
  116. package/lib/values.ts +0 -27
  117. package/react/README.md +0 -67
  118. package/react/hooks/useMutation.ts +0 -89
  119. package/react/hooks/usePaginatedQuery.ts +0 -213
  120. package/react/hooks/useQuery.ts +0 -106
  121. package/react/shared/queryShared.ts +0 -174
  122. package/server/README.md +0 -218
  123. package/server/auth.ts +0 -107
  124. package/server/database/builders.ts +0 -83
  125. package/server/database/context.ts +0 -327
  126. package/server/database/populate.ts +0 -234
  127. package/server/database/query-builder.ts +0 -161
  128. package/server/database/query-utils.ts +0 -25
  129. package/server/db.ts +0 -2
  130. package/server/storage/auth.ts +0 -16
  131. package/server/storage/bucket.ts +0 -22
  132. package/server/storage/context.ts +0 -34
  133. package/server/storage/index.ts +0 -38
  134. package/server/storage/operations.ts +0 -149
  135. package/server/storage/route-handler.ts +0 -60
  136. package/server/storage/types.ts +0 -55
  137. package/server/storage/utils.ts +0 -47
  138. package/server/storage.ts +0 -6
  139. package/server/types/schema-refs.ts +0 -66
  140. package/server/types/types.ts +0 -633
  141. 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
- }