akanjs 3.0.0-alpha.13 → 3.0.0-alpha.15

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.
@@ -31,18 +31,24 @@ type Purified<O> = O extends BaseObject
31
31
  : O extends object
32
32
  ? PurifiedModel<O>
33
33
  : O;
34
- type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
35
- [K in StateKeys as null extends T[K] ? never : K]: Purified<T[K]>;
36
- } & {
37
- [K in StateKeys as null extends T[K] ? K : never]?: Purified<T[K]> | undefined;
38
- };
39
- export type PurifiedModel<T> = T extends (infer S)[]
40
- ? PurifiedModel<S>[]
41
- : T extends string | number | boolean | Dayjs | File
34
+ type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> =
35
+
36
+ unknown extends T
42
37
  ? T
43
- : T extends Map<infer K, infer V>
44
- ? Map<K, PurifiedModel<V>>
45
- : PurifiedWithObjectToId<T>;
38
+ : {
39
+ [K in StateKeys as null extends T[K] ? never : K]: Purified<T[K]>;
40
+ } & {
41
+ [K in StateKeys as null extends T[K] ? K : never]?: Purified<T[K]> | undefined;
42
+ };
43
+ export type PurifiedModel<T> = unknown extends T
44
+ ? T
45
+ : T extends (infer S)[]
46
+ ? PurifiedModel<S>[]
47
+ : T extends string | number | boolean | Dayjs | File
48
+ ? T
49
+ : T extends Map<infer K, infer V>
50
+ ? Map<K, PurifiedModel<V>>
51
+ : PurifiedWithObjectToId<T>;
46
52
 
47
53
  export type UploadableClientArg<T> = [T] extends [File[]] ? File[] | FileList : T;
48
54
 
package/constant/types.ts CHANGED
@@ -14,18 +14,20 @@ type ObjectToId<O> = O extends BaseObject
14
14
  ? DocumentModel<O>
15
15
  : O;
16
16
 
17
- type Docify<T, _StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
18
- [K in _StateKeys as null extends T[K] ? never : K]-?: ObjectToId<NonNullable<T[K]>>;
19
- } & {
20
- [K in _StateKeys as null extends T[K] ? K : never]?: ObjectToId<NonNullable<T[K]>> | undefined;
21
- };
22
- export type DocumentModel<T> = T extends (infer S)[]
23
- ? DocumentModel<S>[]
24
- : T extends string | number | boolean | Dayjs | File
25
- ? T
26
- : T extends Map<infer K, infer V>
27
- ? Map<K, DocumentModel<V>>
28
- : Docify<T>;
17
+ type Docify<T, _StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = unknown extends T
18
+ ? T
19
+ : { [K in _StateKeys as null extends T[K] ? never : K]-?: ObjectToId<NonNullable<T[K]>> } & {
20
+ [K in _StateKeys as null extends T[K] ? K : never]?: ObjectToId<NonNullable<T[K]>> | undefined;
21
+ };
22
+ export type DocumentModel<T> = unknown extends T
23
+ ? T
24
+ : T extends (infer S)[]
25
+ ? DocumentModel<S>[]
26
+ : T extends string | number | boolean | Dayjs | File
27
+ ? T
28
+ : T extends Map<infer K, infer V>
29
+ ? Map<K, DocumentModel<V>>
30
+ : Docify<T>;
29
31
 
30
32
  export type FieldState<T> = T extends { id: string } ? T | null : T;
31
33
  export type DefaultOf<S> = GetStateObject<{ [K in keyof S]: FieldState<S[K]> }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.0.0-alpha.13",
3
+ "version": "3.0.0-alpha.15",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/server/akanApp.ts CHANGED
@@ -190,10 +190,16 @@ export class AkanApp {
190
190
  return Math.max(min, parsed);
191
191
  }
192
192
 
193
+ /**
194
+ * The command that started this gateway outranks an inherited `NODE_ENV`: the command is a statement about
195
+ * this run, while the env var can arrive from a shell export, a CI image, or the workspace `.env` Bun loads
196
+ * on its own. Handing a dev child `NODE_ENV=production` makes it serve from the production route cache and
197
+ * throw on every route, since only `akan build` writes the routes manifest that cache expects.
198
+ */
193
199
  static #defaultChildNodeEnv() {
194
- if (process.env.NODE_ENV) return process.env.NODE_ENV;
195
200
  if (process.env.AKAN_COMMAND_TYPE === "start") return "development";
196
201
  if (process.env.AKAN_COMMAND_TYPE === "build") return "production";
202
+ if (process.env.NODE_ENV) return process.env.NODE_ENV;
197
203
  return Bun.main.endsWith(".js") ? "production" : "development";
198
204
  }
199
205
 
@@ -287,7 +287,13 @@ export class WebRouter {
287
287
  #subRoutes: Record<string, string[]>;
288
288
  #rsc: RscWorker;
289
289
  #hub: HmrWsHub | null = null;
290
- #prodMode = process.env.NODE_ENV === "production";
290
+ /**
291
+ * `akan start` is the dev server whatever the environment claims. Its artifact directory carries no routes
292
+ * manifest — only `akan build` writes one — so the production branch cannot build a route on demand and
293
+ * throws on every request instead. `NODE_ENV` arrives by accident often enough (a workspace `.env` Bun loads
294
+ * on its own, a CI image default) that the command which started this process has to outrank it.
295
+ */
296
+ #prodMode = process.env.NODE_ENV === "production" && process.env.AKAN_COMMAND_TYPE !== "start";
291
297
  #builderRpc: BuilderRpc | null;
292
298
  #routeCache: RouteClientCache;
293
299
  #devHmr: DevHmrController | null = null;
@@ -316,6 +322,8 @@ export class WebRouter {
316
322
  #seedIndex: RouteSeedIndex;
317
323
  constructor({ artifact, cssBytesByUrl, rsc, seedIndex, upgradeHmrWs }: WebRouterOptions) {
318
324
  this.#logger.verbose(`[SSR] loaded ${Object.keys(cssBytesByUrl).length} CSS assets`);
325
+ if (process.env.NODE_ENV === "production" && !this.#prodMode)
326
+ this.#logger.warn("[SSR] NODE_ENV=production ignored under `akan start`; serving in dev mode");
319
327
  this.#artifact = artifact;
320
328
  const { subRoutes, ignoredBasePaths } = resolveSubRouteHosts({
321
329
  subRoutes: artifact.subRoutes,
@@ -1,12 +1,12 @@
1
1
  import { type Dayjs, type GetStateObject } from "akanjs/base";
2
2
  import { type BaseObject, type ConstantModelRef, type DefaultOf, type DefaultOfSchema } from ".";
3
3
  type Purified<O> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? Dayjs : O extends object ? PurifiedModel<O> : O;
4
- type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
4
+ type PurifiedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = unknown extends T ? T : {
5
5
  [K in StateKeys as null extends T[K] ? never : K]: Purified<T[K]>;
6
6
  } & {
7
7
  [K in StateKeys as null extends T[K] ? K : never]?: Purified<T[K]> | undefined;
8
8
  };
9
- export type PurifiedModel<T> = T extends (infer S)[] ? PurifiedModel<S>[] : T extends string | number | boolean | Dayjs | File ? T : T extends Map<infer K, infer V> ? Map<K, PurifiedModel<V>> : PurifiedWithObjectToId<T>;
9
+ export type PurifiedModel<T> = unknown extends T ? T : T extends (infer S)[] ? PurifiedModel<S>[] : T extends string | number | boolean | Dayjs | File ? T : T extends Map<infer K, infer V> ? Map<K, PurifiedModel<V>> : PurifiedWithObjectToId<T>;
10
10
  export type UploadableClientArg<T> = [T] extends [File[]] ? File[] | FileList : T;
11
11
  export type PurifyFunc<Input, _DefaultInput = DefaultOf<Input>, _PurifiedInput = PurifiedModel<Input>> = (self: _DefaultInput, isChild?: boolean) => _PurifiedInput | null;
12
12
  export type PurifyFuncV2<Input, RelationKey extends string = never, _DefaultInput = DefaultOfSchema<Input, RelationKey>, _PurifiedInput = PurifiedModel<Input>> = (self: _DefaultInput, isChild?: boolean) => _PurifiedInput | null;
@@ -2,12 +2,12 @@ import { type Dayjs, type GetStateObject } from "akanjs/base";
2
2
  export type QueryOf<T = any> = any;
3
3
  export type ConstantType = "input" | "object" | "full" | "light" | "insight" | "scalar";
4
4
  type ObjectToId<O> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? Dayjs : O extends object ? DocumentModel<O> : O;
5
- type Docify<T, _StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
5
+ type Docify<T, _StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = unknown extends T ? T : {
6
6
  [K in _StateKeys as null extends T[K] ? never : K]-?: ObjectToId<NonNullable<T[K]>>;
7
7
  } & {
8
8
  [K in _StateKeys as null extends T[K] ? K : never]?: ObjectToId<NonNullable<T[K]>> | undefined;
9
9
  };
10
- export type DocumentModel<T> = T extends (infer S)[] ? DocumentModel<S>[] : T extends string | number | boolean | Dayjs | File ? T : T extends Map<infer K, infer V> ? Map<K, DocumentModel<V>> : Docify<T>;
10
+ export type DocumentModel<T> = unknown extends T ? T : T extends (infer S)[] ? DocumentModel<S>[] : T extends string | number | boolean | Dayjs | File ? T : T extends Map<infer K, infer V> ? Map<K, DocumentModel<V>> : Docify<T>;
11
11
  export type FieldState<T> = T extends {
12
12
  id: string;
13
13
  } ? T | null : T;