akanjs 2.3.11-rc.6 → 2.3.11-rc.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "2.3.11-rc.6",
3
+ "version": "2.3.11-rc.7",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -49,7 +49,12 @@ export class LocaleWebProxy implements WebProxy {
49
49
  (locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`,
50
50
  );
51
51
 
52
- if (!isInternalProxyRequest(requestUrl) && !isWellKnownRequest(pathname) && pathnameIsMissingLocale) {
52
+ if (
53
+ !isInternalProxyRequest(requestUrl) &&
54
+ !isWellKnownRequest(pathname) &&
55
+ !isApiRequest(pathname) &&
56
+ pathnameIsMissingLocale
57
+ ) {
53
58
  return Response.redirect(
54
59
  new URL(`/${getLocale(request)}/${pathname.slice(1)}${targetUrl.search}`, getPublicRequestUrl(request)),
55
60
  307,
@@ -90,3 +95,7 @@ function isInternalProxyRequest(requestUrl: URL): boolean {
90
95
  function isWellKnownRequest(pathname: string): boolean {
91
96
  return pathname === "/.well-known" || pathname.startsWith("/.well-known/");
92
97
  }
98
+
99
+ function isApiRequest(pathname: string): boolean {
100
+ return pathname === "/api" || pathname.startsWith("/api/");
101
+ }
@@ -158,6 +158,16 @@ export class SignalResolver {
158
158
  const serviceName = `${refName}Service`;
159
159
  const capitalizedRefName = capitalize(refName);
160
160
 
161
+ const assertSliceQuery = (query: unknown, key: string) => {
162
+ if (Array.isArray(query))
163
+ throw new Error(
164
+ `Slice "${refName}.${key}" exec returned an array instead of a query descriptor. ` +
165
+ `Return a query from the slice's service (e.g. this.${refName}Service.queryBy...(...)), ` +
166
+ `not an executed list (listBy.../findMany...), which resolves to an array.`,
167
+ );
168
+ return query;
169
+ };
170
+
161
171
  class SliceEndpoint extends sliceEndpoint(sliceCls.srv, (builder) => {
162
172
  const endpointObj: { [key: string]: EndpointInfo } = {};
163
173
  Object.entries(sliceMeta).forEach(([key, sliceInfo]) => {
@@ -179,7 +189,10 @@ export class SignalResolver {
179
189
  const limit = Number(requestArgs[argLength + 1] ?? 20);
180
190
  const sort = requestArgs[argLength + 2] ?? "latest";
181
191
  const internalArgs = requestArgs.slice(argLength + 3);
182
- const query = await sliceInfo.execFn?.apply(this, [...args, ...internalArgs, documentQueryHelper]);
192
+ const query = assertSliceQuery(
193
+ await sliceInfo.execFn?.apply(this, [...args, ...internalArgs, documentQueryHelper]),
194
+ key,
195
+ );
183
196
  return (await this[serviceName].__list(query, {
184
197
  skip,
185
198
  limit,
@@ -196,7 +209,10 @@ export class SignalResolver {
196
209
  .exec(async function (this: any, ...requestArgs: any) {
197
210
  const args = requestArgs.slice(0, argLength);
198
211
  const internalArgs = requestArgs.slice(argLength);
199
- const query = await sliceInfo.execFn?.apply(this, [...args, ...internalArgs, documentQueryHelper]);
212
+ const query = assertSliceQuery(
213
+ await sliceInfo.execFn?.apply(this, [...args, ...internalArgs, documentQueryHelper]),
214
+ key,
215
+ );
200
216
  return await this[serviceName].__insight(query);
201
217
  });
202
218
  });
@@ -816,7 +816,15 @@ class QueryCompiler {
816
816
  private assertPath(path: string) {
817
817
  const root = path.split(".")[0];
818
818
  if (BASE_COLUMNS.has(root)) return;
819
- if (!this.fields[root]) throw new Error(`Unknown document field path: ${path}`);
819
+ if (!this.fields[root]) {
820
+
821
+ if (/^\d+$/.test(root))
822
+ throw new Error(
823
+ `Query received an array instead of a query object (field path "${path}"). ` +
824
+ `A query must be a descriptor object; a slice exec must return queryBy...(...), not an executed list.`,
825
+ );
826
+ throw new Error(`Unknown document field path: ${path}`);
827
+ }
820
828
  }
821
829
 
822
830
  private isQueryNode(value: unknown): value is DocumentQueryNode {