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.
- package/cli/commands/index.ts +140 -0
- package/cli/generate.ts +149 -0
- package/cli/index.ts +56 -447
- package/cli/load-config.ts +182 -0
- package/cli/schema-compiler.ts +657 -0
- package/cli/templates/auth/README.md +156 -0
- package/cli/templates/auth/config.ts +61 -0
- package/cli/templates/auth/route-config.ts +18 -0
- package/cli/templates/auth/route-handler.ts +18 -0
- package/cli/templates/auth/route-request-utils.ts +55 -0
- package/cli/templates/auth/route.ts +14 -0
- package/cli/templates/core/README.md +266 -0
- package/cli/templates/core/app-creation.ts +19 -0
- package/cli/templates/core/client/appflare.ts +37 -0
- package/cli/templates/core/client/index.ts +6 -0
- package/cli/templates/core/client/storage.ts +100 -0
- package/cli/templates/core/client/types.ts +54 -0
- package/cli/templates/core/client-modules/appflare.ts +112 -0
- package/cli/templates/core/client-modules/handlers/index.ts +740 -0
- package/cli/templates/core/client-modules/handlers.ts +1 -0
- package/cli/templates/core/client-modules/index.ts +7 -0
- package/cli/templates/core/client-modules/storage.ts +180 -0
- package/cli/templates/core/client-modules/types.ts +145 -0
- package/cli/templates/core/client.ts +39 -0
- package/cli/templates/core/drizzle.ts +15 -0
- package/cli/templates/core/export.ts +14 -0
- package/cli/templates/core/handlers-route.ts +23 -0
- package/cli/templates/core/handlers.ts +1 -0
- package/cli/templates/core/imports.ts +8 -0
- package/cli/templates/core/server.ts +38 -0
- package/cli/templates/core/types.ts +6 -0
- package/cli/templates/core/wrangler.ts +109 -0
- package/cli/templates/handlers/README.md +265 -0
- package/cli/templates/handlers/auth.ts +36 -0
- package/cli/templates/handlers/execution.ts +39 -0
- package/cli/templates/handlers/generators/context/context-creation.ts +80 -0
- package/cli/templates/handlers/generators/context/error-helpers.ts +11 -0
- package/cli/templates/handlers/generators/context/scheduler.ts +24 -0
- package/cli/templates/handlers/generators/context/storage-api.ts +112 -0
- package/cli/templates/handlers/generators/context/storage-helpers.ts +59 -0
- package/cli/templates/handlers/generators/context/types.ts +18 -0
- package/cli/templates/handlers/generators/context.ts +43 -0
- package/cli/templates/handlers/generators/execution.ts +15 -0
- package/cli/templates/handlers/generators/handlers.ts +13 -0
- package/cli/templates/handlers/index.ts +43 -0
- package/cli/templates/handlers/operations.ts +116 -0
- package/cli/templates/handlers/registration.ts +1114 -0
- package/cli/templates/handlers/types.ts +960 -0
- package/cli/templates/handlers/utils.ts +48 -0
- package/cli/types.ts +108 -0
- package/cli/utils/handler-discovery.ts +366 -0
- package/cli/utils/json-utils.ts +24 -0
- package/cli/utils/path-utils.ts +19 -0
- package/cli/utils/schema-discovery.ts +390 -0
- package/index.ts +27 -4
- package/package.json +23 -20
- package/react/index.ts +5 -3
- package/react/use-infinite-query.ts +190 -0
- package/react/use-mutation.ts +54 -0
- package/react/use-query.ts +158 -0
- package/schema.ts +262 -0
- package/tsconfig.json +2 -4
- package/cli/README.md +0 -108
- package/cli/core/build.ts +0 -187
- package/cli/core/config.ts +0 -92
- package/cli/core/discover-handlers.ts +0 -143
- package/cli/core/handlers.ts +0 -7
- package/cli/core/index.ts +0 -205
- package/cli/generators/generate-api-client/client.ts +0 -163
- package/cli/generators/generate-api-client/extract-configuration.ts +0 -121
- package/cli/generators/generate-api-client/index.ts +0 -973
- package/cli/generators/generate-api-client/types.ts +0 -164
- package/cli/generators/generate-api-client/utils.ts +0 -22
- package/cli/generators/generate-api-client.ts +0 -1
- package/cli/generators/generate-cloudflare-worker/helpers.ts +0 -24
- package/cli/generators/generate-cloudflare-worker/index.ts +0 -2
- package/cli/generators/generate-cloudflare-worker/worker.ts +0 -148
- package/cli/generators/generate-cloudflare-worker/wrangler.ts +0 -108
- package/cli/generators/generate-cloudflare-worker.ts +0 -4
- package/cli/generators/generate-cron-handlers/cron-handlers-block.ts +0 -2
- package/cli/generators/generate-cron-handlers/handler-entries.ts +0 -29
- package/cli/generators/generate-cron-handlers/index.ts +0 -61
- package/cli/generators/generate-cron-handlers/runtime-block.ts +0 -49
- package/cli/generators/generate-cron-handlers/type-helpers-block.ts +0 -60
- package/cli/generators/generate-db-handlers/index.ts +0 -33
- package/cli/generators/generate-db-handlers/prepare.ts +0 -24
- package/cli/generators/generate-db-handlers/templates.ts +0 -189
- package/cli/generators/generate-db-handlers.ts +0 -1
- package/cli/generators/generate-hono-server/auth.ts +0 -97
- package/cli/generators/generate-hono-server/imports.ts +0 -55
- package/cli/generators/generate-hono-server/index.ts +0 -52
- package/cli/generators/generate-hono-server/routes.ts +0 -115
- package/cli/generators/generate-hono-server/template.ts +0 -371
- package/cli/generators/generate-hono-server.ts +0 -1
- package/cli/generators/generate-scheduler-handlers/constants.ts +0 -8
- package/cli/generators/generate-scheduler-handlers/handler-entries.ts +0 -22
- package/cli/generators/generate-scheduler-handlers/index.ts +0 -51
- package/cli/generators/generate-scheduler-handlers/runtime-block.ts +0 -68
- package/cli/generators/generate-scheduler-handlers/scheduler-handlers-block.ts +0 -2
- package/cli/generators/generate-scheduler-handlers/type-helpers-block.ts +0 -68
- package/cli/generators/generate-scheduler-handlers.ts +0 -1
- package/cli/generators/generate-websocket-durable-object/auth.ts +0 -30
- package/cli/generators/generate-websocket-durable-object/imports.ts +0 -55
- package/cli/generators/generate-websocket-durable-object/index.ts +0 -41
- package/cli/generators/generate-websocket-durable-object/query-handlers.ts +0 -18
- package/cli/generators/generate-websocket-durable-object/template.ts +0 -714
- package/cli/generators/generate-websocket-durable-object.ts +0 -1
- package/cli/schema/schema-static-types.ts +0 -702
- package/cli/schema/schema.ts +0 -151
- package/cli/utils/tsc.ts +0 -54
- package/cli/utils/utils.ts +0 -190
- package/cli/utils/zod-utils.ts +0 -121
- package/lib/README.md +0 -50
- package/lib/db.ts +0 -19
- package/lib/location.ts +0 -110
- package/lib/values.ts +0 -27
- package/react/README.md +0 -67
- package/react/hooks/useMutation.ts +0 -89
- package/react/hooks/usePaginatedQuery.ts +0 -213
- package/react/hooks/useQuery.ts +0 -106
- package/react/shared/queryShared.ts +0 -174
- package/server/README.md +0 -218
- package/server/auth.ts +0 -107
- package/server/database/builders.ts +0 -83
- package/server/database/context.ts +0 -327
- package/server/database/populate.ts +0 -234
- package/server/database/query-builder.ts +0 -161
- package/server/database/query-utils.ts +0 -25
- package/server/db.ts +0 -2
- package/server/storage/auth.ts +0 -16
- package/server/storage/bucket.ts +0 -22
- package/server/storage/context.ts +0 -34
- package/server/storage/index.ts +0 -38
- package/server/storage/operations.ts +0 -149
- package/server/storage/route-handler.ts +0 -60
- package/server/storage/types.ts +0 -55
- package/server/storage/utils.ts +0 -47
- package/server/storage.ts +0 -6
- package/server/types/schema-refs.ts +0 -66
- package/server/types/types.ts +0 -633
- package/server/utils/id-utils.ts +0 -230
package/server/utils/id-utils.ts
DELETED
|
@@ -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
|
-
}
|