better-convex 0.6.3 → 0.7.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/dist/aggregate/index.d.ts +388 -0
- package/dist/aggregate/index.js +37 -0
- package/dist/{auth-client → auth/client}/index.js +1 -1
- package/dist/auth/http/index.d.ts +63 -0
- package/dist/auth/http/index.js +429 -0
- package/dist/auth/index.d.ts +19001 -185
- package/dist/auth/index.js +373 -686
- package/dist/{auth-nextjs → auth/nextjs}/index.d.ts +3 -4
- package/dist/{auth-nextjs → auth/nextjs}/index.js +3 -5
- package/dist/{caller-factory-B1FvYSKr.js → caller-factory-Dmgv8MLS.js} +15 -12
- package/dist/cli.mjs +2601 -13
- package/dist/codegen-Cz1idI3-.mjs +969 -0
- package/dist/{create-schema-orm-DplxTtYj.js → create-schema-orm-69VF4CFV.js} +4 -3
- package/dist/crpc/index.d.ts +2 -2
- package/dist/crpc/index.js +3 -3
- package/dist/{http-types-BRLY10NX.d.ts → http-types-BCf2wCgp.d.ts} +25 -25
- package/dist/meta-utils-DDVYp9Xf.js +117 -0
- package/dist/orm/index.d.ts +4 -3012
- package/dist/orm/index.js +9631 -2
- package/dist/{index-BQkhP2ny.d.ts → procedure-caller-CcjtUFvL.d.ts} +211 -74
- package/dist/query-context-BDSis9rT.js +1518 -0
- package/dist/query-context-DGExXZIV.d.ts +42 -0
- package/dist/react/index.d.ts +31 -35
- package/dist/react/index.js +145 -58
- package/dist/rsc/index.d.ts +4 -7
- package/dist/rsc/index.js +14 -10
- package/dist/runtime-B9xQFY8W.js +2280 -0
- package/dist/server/index.d.ts +3 -4
- package/dist/server/index.js +384 -10
- package/dist/{types-o-5rYcTr.d.ts → types-CIBGEYXq.d.ts} +4 -3
- package/dist/types-DgwvxKbT.d.ts +4 -0
- package/dist/watcher.mjs +8 -8
- package/dist/where-clause-compiler-CRP-i1Qa.d.ts +3463 -0
- package/package.json +14 -10
- package/dist/codegen-DkpPBVPn.mjs +0 -189
- package/dist/context-utils-DSuX99Da.d.ts +0 -17
- package/dist/meta-utils-DCpLSBWB.js +0 -41
- package/dist/orm-CleikBIV.js +0 -8820
- /package/dist/{auth-client → auth/client}/index.d.ts +0 -0
- /package/dist/{auth-config → auth/config}/index.d.ts +0 -0
- /package/dist/{auth-config → auth/config}/index.js +0 -0
- /package/dist/{create-schema-DhWXOhnU.js → create-schema-BdZOL6ns.js} +0 -0
- /package/dist/{customFunctions-C1okqCzL.js → customFunctions-CZnCwoR3.js} +0 -0
- /package/dist/{error-BZUhlhYz.js → error-Be4OcwwD.js} +0 -0
- /package/dist/{query-options-BL1Q0X7q.js → query-options-B0c1b6pZ.js} +0 -0
- /package/dist/{transformer-CTNSPjwp.js → transformer-Dh0w2py0.js} +0 -0
- /package/dist/{types-jftzhhuc.d.ts → types-DwGkkq2s.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { indexFields } from "./create-schema-
|
|
1
|
+
import { indexFields } from "./create-schema-BdZOL6ns.js";
|
|
2
2
|
|
|
3
3
|
//#region src/auth/create-schema-orm.ts
|
|
4
4
|
const specialFields = (tables) => Object.fromEntries(Object.entries(tables).map(([key, table]) => {
|
|
@@ -16,6 +16,7 @@ const mergedIndexFields = (tables) => Object.fromEntries(Object.entries(tables).
|
|
|
16
16
|
const VALID_IDENTIFIER_REGEX = /^[$A-Z_][0-9A-Z_$]*$/i;
|
|
17
17
|
const LEADING_DIGIT_REGEX = /^[0-9]/;
|
|
18
18
|
const renderObjectKey = (value) => VALID_IDENTIFIER_REGEX.test(value) ? value : JSON.stringify(value);
|
|
19
|
+
const renderPropertyAccess = (objectName, propertyName) => VALID_IDENTIFIER_REGEX.test(propertyName) ? `${objectName}.${propertyName}` : `${objectName}[${JSON.stringify(propertyName)}]`;
|
|
19
20
|
const toIdentifier = (value) => {
|
|
20
21
|
const normalized = value.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
21
22
|
if (!normalized) return "_table";
|
|
@@ -100,7 +101,7 @@ const createSchemaOrm = async ({ file, tables }) => {
|
|
|
100
101
|
if (attr.references) {
|
|
101
102
|
const referencedEntry = findTableEntryByModel(entries, tables, attr.references.model) ?? { varName: toIdentifier(attr.references.model) };
|
|
102
103
|
const targetField = getReferencedFieldName(tables, entries, attr.references.model, attr.references.field);
|
|
103
|
-
expression += `.references(() => ${referencedEntry.varName
|
|
104
|
+
expression += `.references(() => ${renderPropertyAccess(referencedEntry.varName, targetField)})`;
|
|
104
105
|
}
|
|
105
106
|
return ` ${key}: ${expression},`;
|
|
106
107
|
});
|
|
@@ -108,7 +109,7 @@ const createSchemaOrm = async ({ file, tables }) => {
|
|
|
108
109
|
const indexArray = Array.isArray(indexSpec) ? [...indexSpec].sort() : [indexSpec];
|
|
109
110
|
const indexName = indexArray.join("_");
|
|
110
111
|
state.ormImports.add("index");
|
|
111
|
-
const fieldsCall = indexArray.map((fieldName) =>
|
|
112
|
+
const fieldsCall = indexArray.map((fieldName) => renderPropertyAccess(entry.varName, fieldName)).join(", ");
|
|
112
113
|
return `index(${JSON.stringify(indexName)}).on(${fieldsCall})`;
|
|
113
114
|
}) || [];
|
|
114
115
|
const extraConfig = indexes.length > 0 ? `,\n (${entry.varName}) => [\n ${indexes.join(",\n ")},\n ]` : "";
|
package/dist/crpc/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as identityTransformer, G as DataTransformerOptions, H as CombinedDataTransformer, J as dateWireCodec, K as WireCodec, Q as getTransformer, U as DATE_CODEC_TAG, W as DataTransformer, X as defaultCRPCTransformer, Y as decodeWire, Z as encodeWire, a as HttpProcedureCall, c as InferHttpInput, i as HttpErrorCode, l as InferHttpOutput, n as HttpClientError, o as HttpRouteInfo, q as createTaggedTransformer, r as HttpClientFromRouter, s as HttpRouteMap, t as HttpClient, u as isHttpClientError } from "../http-types-
|
|
2
|
-
import { C as PaginatedFnMeta, D as VanillaMutation, E as VanillaCRPCClient, O as VanillaQuery, S as Meta, T as VanillaAction, _ as ExtractPaginatedItem, a as ConvexInfiniteQueryMeta, b as InfiniteQueryInput, c as ConvexMutationKey, d as ConvexQueryMeta, f as ConvexQueryOptions, g as DecorateQuery, h as DecorateMutation, i as ConvexActionOptions, l as ConvexQueryHookOptions, m as DecorateInfiniteQuery, n as CRPCClient, o as ConvexInfiniteQueryOptions, p as DecorateAction, r as ConvexActionKey, s as ConvexInfiniteQueryOptionsWithRef, t as AuthType, u as ConvexQueryKey, v as FUNC_REF_SYMBOL, w as PaginationOpts, x as InfiniteQueryOptsParam, y as FnMeta } from "../types-
|
|
1
|
+
import { $ as identityTransformer, G as DataTransformerOptions, H as CombinedDataTransformer, J as dateWireCodec, K as WireCodec, Q as getTransformer, U as DATE_CODEC_TAG, W as DataTransformer, X as defaultCRPCTransformer, Y as decodeWire, Z as encodeWire, a as HttpProcedureCall, c as InferHttpInput, i as HttpErrorCode, l as InferHttpOutput, n as HttpClientError, o as HttpRouteInfo, q as createTaggedTransformer, r as HttpClientFromRouter, s as HttpRouteMap, t as HttpClient, u as isHttpClientError } from "../http-types-BCf2wCgp.js";
|
|
2
|
+
import { C as PaginatedFnMeta, D as VanillaMutation, E as VanillaCRPCClient, O as VanillaQuery, S as Meta, T as VanillaAction, _ as ExtractPaginatedItem, a as ConvexInfiniteQueryMeta, b as InfiniteQueryInput, c as ConvexMutationKey, d as ConvexQueryMeta, f as ConvexQueryOptions, g as DecorateQuery, h as DecorateMutation, i as ConvexActionOptions, l as ConvexQueryHookOptions, m as DecorateInfiniteQuery, n as CRPCClient, o as ConvexInfiniteQueryOptions, p as DecorateAction, r as ConvexActionKey, s as ConvexInfiniteQueryOptionsWithRef, t as AuthType, u as ConvexQueryKey, v as FUNC_REF_SYMBOL, w as PaginationOpts, x as InfiniteQueryOptsParam, y as FnMeta } from "../types-CIBGEYXq.js";
|
|
3
3
|
import { FunctionArgs, FunctionReference } from "convex/server";
|
|
4
4
|
|
|
5
5
|
//#region src/crpc/error.d.ts
|
package/dist/crpc/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as isCRPCErrorCode, i as isCRPCError, n as defaultIsUnauthorized, r as isCRPCClientError, t as CRPCClientError } from "../error-
|
|
2
|
-
import { a as defaultCRPCTransformer, c as identityTransformer, i as decodeWire, n as createTaggedTransformer, o as encodeWire, r as dateWireCodec, s as getTransformer, t as DATE_CODEC_TAG } from "../transformer-
|
|
3
|
-
import { n as convexInfiniteQueryOptions, r as convexQuery, t as convexAction } from "../query-options-
|
|
1
|
+
import { a as isCRPCErrorCode, i as isCRPCError, n as defaultIsUnauthorized, r as isCRPCClientError, t as CRPCClientError } from "../error-Be4OcwwD.js";
|
|
2
|
+
import { a as defaultCRPCTransformer, c as identityTransformer, i as decodeWire, n as createTaggedTransformer, o as encodeWire, r as dateWireCodec, s as getTransformer, t as DATE_CODEC_TAG } from "../transformer-Dh0w2py0.js";
|
|
3
|
+
import { n as convexInfiniteQueryOptions, r as convexQuery, t as convexAction } from "../query-options-B0c1b6pZ.js";
|
|
4
4
|
|
|
5
5
|
//#region src/crpc/http-types.ts
|
|
6
6
|
/** HTTP client error */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as Simplify$1 } from "./types-
|
|
1
|
+
import { o as Simplify$1 } from "./types-DwGkkq2s.js";
|
|
2
2
|
import { GenericActionCtx, GenericDataModel, HttpRouter } from "convex/server";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { Context, Hono } from "hono";
|
|
@@ -8,8 +8,8 @@ import { Context, Hono } from "hono";
|
|
|
8
8
|
* Generic transformer contract (mirrors tRPC shape).
|
|
9
9
|
*/
|
|
10
10
|
interface DataTransformer {
|
|
11
|
-
serialize(object: any): any;
|
|
12
11
|
deserialize(object: any): any;
|
|
12
|
+
serialize(object: any): any;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Separate input/output transformers.
|
|
@@ -26,10 +26,10 @@ type DataTransformerOptions = CombinedDataTransformer | DataTransformer;
|
|
|
26
26
|
* Extensible tagged wire codec.
|
|
27
27
|
*/
|
|
28
28
|
interface WireCodec {
|
|
29
|
-
readonly tag: `$${string}`;
|
|
30
|
-
isType(value: unknown): boolean;
|
|
31
|
-
encode(value: unknown): unknown;
|
|
32
29
|
decode(value: unknown): unknown;
|
|
30
|
+
encode(value: unknown): unknown;
|
|
31
|
+
isType(value: unknown): boolean;
|
|
32
|
+
readonly tag: `$${string}`;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Date wire tag (Convex-style reserved key).
|
|
@@ -154,8 +154,8 @@ type AnyMiddlewareBuilder = MiddlewareBuilder<any, any, any, any>;
|
|
|
154
154
|
type ProcedureMeta = object;
|
|
155
155
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
156
156
|
interface HttpRouteDefinition<TMethod extends HttpMethod = HttpMethod> {
|
|
157
|
-
path: string;
|
|
158
157
|
method: TMethod;
|
|
158
|
+
path: string;
|
|
159
159
|
pathParamNames: string[];
|
|
160
160
|
usePathPrefix: boolean;
|
|
161
161
|
}
|
|
@@ -168,19 +168,6 @@ type InferHttpInput$1<T> = T extends UnsetMarker ? undefined : T extends z.ZodTy
|
|
|
168
168
|
* Stores schema types directly (like QueryProcedureBuilder)
|
|
169
169
|
*/
|
|
170
170
|
interface HttpProcedureBuilderDef<TCtx, TInput extends UnsetMarker | z.ZodTypeAny, TOutput extends UnsetMarker | z.ZodTypeAny, TParams extends UnsetMarker | z.ZodTypeAny, TQuery extends UnsetMarker | z.ZodTypeAny, TMeta extends ProcedureMeta, TMethod extends HttpMethod = HttpMethod, TForm extends UnsetMarker | z.ZodTypeAny = UnsetMarker> {
|
|
171
|
-
middlewares: AnyMiddleware[];
|
|
172
|
-
meta: TMeta;
|
|
173
|
-
inputSchema?: z.ZodTypeAny;
|
|
174
|
-
outputSchema?: z.ZodTypeAny;
|
|
175
|
-
paramsSchema?: z.ZodTypeAny;
|
|
176
|
-
querySchema?: z.ZodTypeAny;
|
|
177
|
-
formSchema?: z.ZodTypeAny;
|
|
178
|
-
route?: HttpRouteDefinition<TMethod>;
|
|
179
|
-
functionConfig: {
|
|
180
|
-
base: HttpActionConstructor;
|
|
181
|
-
createContext: (ctx: GenericActionCtx<GenericDataModel>) => TCtx;
|
|
182
|
-
transformer: CombinedDataTransformer;
|
|
183
|
-
};
|
|
184
171
|
/** @internal Phantom types for type inference */
|
|
185
172
|
_types?: {
|
|
186
173
|
input: TInput;
|
|
@@ -189,6 +176,19 @@ interface HttpProcedureBuilderDef<TCtx, TInput extends UnsetMarker | z.ZodTypeAn
|
|
|
189
176
|
query: TQuery;
|
|
190
177
|
form: TForm;
|
|
191
178
|
};
|
|
179
|
+
formSchema?: z.ZodTypeAny;
|
|
180
|
+
functionConfig: {
|
|
181
|
+
base: HttpActionConstructor;
|
|
182
|
+
createContext: (ctx: GenericActionCtx<GenericDataModel>) => TCtx;
|
|
183
|
+
transformer: CombinedDataTransformer;
|
|
184
|
+
};
|
|
185
|
+
inputSchema?: z.ZodTypeAny;
|
|
186
|
+
meta: TMeta;
|
|
187
|
+
middlewares: AnyMiddleware[];
|
|
188
|
+
outputSchema?: z.ZodTypeAny;
|
|
189
|
+
paramsSchema?: z.ZodTypeAny;
|
|
190
|
+
querySchema?: z.ZodTypeAny;
|
|
191
|
+
route?: HttpRouteDefinition<TMethod>;
|
|
192
192
|
}
|
|
193
193
|
type HttpActionConstructor = (handler: (ctx: GenericActionCtx<GenericDataModel>, request: Request) => Promise<Response>) => HttpActionHandler;
|
|
194
194
|
interface HttpActionHandler {
|
|
@@ -230,11 +230,11 @@ type HttpHandlerOpts<TCtx, TInput extends UnsetMarker | z.ZodTypeAny, TParams ex
|
|
|
230
230
|
* Hono handler with cRPC route metadata attached
|
|
231
231
|
*/
|
|
232
232
|
interface CRPCHonoHandler {
|
|
233
|
-
(c: Context): Promise<Response>;
|
|
234
233
|
_crpcRoute: {
|
|
235
234
|
path: string;
|
|
236
235
|
method: HttpMethod;
|
|
237
236
|
};
|
|
237
|
+
(c: Context): Promise<Response>;
|
|
238
238
|
}
|
|
239
239
|
//#endregion
|
|
240
240
|
//#region src/server/http-router.d.ts
|
|
@@ -248,11 +248,11 @@ interface HttpRouterRecord {
|
|
|
248
248
|
* Router definition - stores both flat procedures and hierarchical record
|
|
249
249
|
*/
|
|
250
250
|
interface HttpRouterDef<TRecord extends HttpRouterRecord> {
|
|
251
|
-
router: true;
|
|
252
251
|
/** Flat map with dot-notation keys (e.g., "todos.get") for lookup */
|
|
253
252
|
procedures: Record<string, HttpProcedure>;
|
|
254
253
|
/** Hierarchical structure for type inference */
|
|
255
254
|
record: TRecord;
|
|
255
|
+
router: true;
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
258
|
* HTTP Router - like tRPC's BuiltRouter
|
|
@@ -284,11 +284,11 @@ declare class HttpRouterWithHono extends HttpRouter {
|
|
|
284
284
|
* });
|
|
285
285
|
*
|
|
286
286
|
* // In http.ts
|
|
287
|
-
* export const
|
|
287
|
+
* export const httpRouter = router({
|
|
288
288
|
* todos: todosRouter,
|
|
289
289
|
* health,
|
|
290
290
|
* });
|
|
291
|
-
* export type AppRouter = typeof
|
|
291
|
+
* export type AppRouter = typeof httpRouter;
|
|
292
292
|
* ```
|
|
293
293
|
*/
|
|
294
294
|
declare function createHttpRouterFactory(): <TRecord extends HttpRouterRecord>(record: TRecord) => CRPCHttpRouter<TRecord>;
|
|
@@ -304,7 +304,7 @@ declare function createHttpRouterFactory(): <TRecord extends HttpRouterRecord>(r
|
|
|
304
304
|
* const app = new Hono();
|
|
305
305
|
* app.use('/api/*', cors({ origin: process.env.SITE_URL, credentials: true }));
|
|
306
306
|
*
|
|
307
|
-
* export default createHttpRouter(app,
|
|
307
|
+
* export default createHttpRouter(app, httpRouter);
|
|
308
308
|
* ```
|
|
309
309
|
*/
|
|
310
310
|
declare function createHttpRouter<TRecord extends HttpRouterRecord>(app: Hono, router: CRPCHttpRouter<TRecord>): HttpRouterWithHono;
|
|
@@ -313,7 +313,7 @@ declare function createHttpRouter<TRecord extends HttpRouterRecord>(app: Hono, r
|
|
|
313
313
|
*
|
|
314
314
|
* @example
|
|
315
315
|
* ```ts
|
|
316
|
-
* export const httpRoutes = extractRouteMap(
|
|
316
|
+
* export const httpRoutes = extractRouteMap(httpRouter._def.procedures);
|
|
317
317
|
* ```
|
|
318
318
|
*/
|
|
319
319
|
declare function extractRouteMap<T extends Record<string, HttpProcedure>>(procedures: T): { [K in keyof T]: {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
//#region src/shared/meta-utils.ts
|
|
2
|
+
const metaCache = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
const nonMetaLeafKeys = new Set(["functionRef", "ref"]);
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === "object" && value !== null;
|
|
6
|
+
}
|
|
7
|
+
function isFunctionType(value) {
|
|
8
|
+
return value === "query" || value === "mutation" || value === "action";
|
|
9
|
+
}
|
|
10
|
+
function isMetaScalar(value) {
|
|
11
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
12
|
+
}
|
|
13
|
+
function extractLeafMeta(value) {
|
|
14
|
+
const type = value.type;
|
|
15
|
+
if (!isFunctionType(type)) return;
|
|
16
|
+
const result = { type };
|
|
17
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
18
|
+
if (key === "type" || nonMetaLeafKeys.has(key) || key.startsWith("_")) continue;
|
|
19
|
+
if (entry === void 0) continue;
|
|
20
|
+
if (isMetaScalar(entry)) result[key] = entry;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
function getHttpRoutes(api) {
|
|
25
|
+
const routes = api._http;
|
|
26
|
+
if (!isRecord(routes)) return;
|
|
27
|
+
const normalized = {};
|
|
28
|
+
for (const [routeKey, routeValue] of Object.entries(routes)) {
|
|
29
|
+
if (!isRecord(routeValue)) continue;
|
|
30
|
+
const routePath = routeValue.path;
|
|
31
|
+
const routeMethod = routeValue.method;
|
|
32
|
+
if (typeof routePath === "string" && typeof routeMethod === "string") normalized[routeKey] = {
|
|
33
|
+
path: routePath,
|
|
34
|
+
method: routeMethod
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return normalized;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a metadata index from merged API leaves.
|
|
41
|
+
* Supports both generated `api` objects and plain metadata fixtures.
|
|
42
|
+
*/
|
|
43
|
+
function buildMetaIndex(api) {
|
|
44
|
+
const cached = metaCache.get(api);
|
|
45
|
+
if (cached) return cached;
|
|
46
|
+
const meta = {};
|
|
47
|
+
const httpRoutes = getHttpRoutes(api);
|
|
48
|
+
if (httpRoutes) meta._http = httpRoutes;
|
|
49
|
+
const walk = (node, path) => {
|
|
50
|
+
for (const [key, value] of Object.entries(node)) {
|
|
51
|
+
if (key.startsWith("_")) continue;
|
|
52
|
+
if (!isRecord(value)) continue;
|
|
53
|
+
const leafMeta = extractLeafMeta(value);
|
|
54
|
+
if (leafMeta) {
|
|
55
|
+
if (path.length === 0) continue;
|
|
56
|
+
const namespace = path.join("/");
|
|
57
|
+
meta[namespace] ??= {};
|
|
58
|
+
meta[namespace][key] = leafMeta;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
walk(value, [...path, key]);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
walk(api, []);
|
|
65
|
+
metaCache.set(api, meta);
|
|
66
|
+
return meta;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get a function reference from the API object by traversing the path.
|
|
70
|
+
*/
|
|
71
|
+
function getFuncRef(api, path) {
|
|
72
|
+
let current = api;
|
|
73
|
+
for (const key of path) if (current && typeof current === "object") {
|
|
74
|
+
const next = current[key];
|
|
75
|
+
if (next === void 0) throw new Error(`Invalid path: ${path.join(".")}`);
|
|
76
|
+
current = next;
|
|
77
|
+
} else throw new Error(`Invalid path: ${path.join(".")}`);
|
|
78
|
+
if (current && typeof current === "object") {
|
|
79
|
+
const maybeFunctionRef = current.functionRef;
|
|
80
|
+
if (maybeFunctionRef && typeof maybeFunctionRef === "object") return maybeFunctionRef;
|
|
81
|
+
}
|
|
82
|
+
if (!current || typeof current !== "object") throw new Error(`Invalid function reference at path: ${path.join(".")}`);
|
|
83
|
+
return current;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get function type from meta using path.
|
|
87
|
+
* Supports nested paths like ['items', 'queries', 'list'] → namespace='items/queries', fn='list'
|
|
88
|
+
*
|
|
89
|
+
* @param path - Path segments like ['todos', 'create'] or ['items', 'queries', 'list']
|
|
90
|
+
* @param meta - The meta object from codegen
|
|
91
|
+
* @returns Function type or 'query' as default
|
|
92
|
+
*/
|
|
93
|
+
function getFunctionType(path, source) {
|
|
94
|
+
if (path.length < 2) return "query";
|
|
95
|
+
const meta = buildMetaIndex(source);
|
|
96
|
+
const fnName = path.at(-1);
|
|
97
|
+
const fnType = meta[path.slice(0, -1).join("/")]?.[fnName]?.type;
|
|
98
|
+
if (fnType === "query" || fnType === "mutation" || fnType === "action") return fnType;
|
|
99
|
+
return "query";
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get function metadata from meta using path.
|
|
103
|
+
* Supports nested paths like ['items', 'queries', 'list'] → namespace='items/queries', fn='list'
|
|
104
|
+
*
|
|
105
|
+
* @param path - Path segments like ['todos', 'create'] or ['items', 'queries', 'list']
|
|
106
|
+
* @param meta - The meta object from codegen
|
|
107
|
+
* @returns Function metadata or undefined
|
|
108
|
+
*/
|
|
109
|
+
function getFunctionMeta(path, source) {
|
|
110
|
+
if (path.length < 2) return;
|
|
111
|
+
const meta = buildMetaIndex(source);
|
|
112
|
+
const fnName = path.at(-1);
|
|
113
|
+
return meta[path.slice(0, -1).join("/")]?.[fnName];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { getFunctionType as i, getFuncRef as n, getFunctionMeta as r, buildMetaIndex as t };
|