akanjs 2.3.11 → 2.3.12-rc.1

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.
@@ -101,6 +101,9 @@ export class FetchClient {
101
101
  : undefined,
102
102
  getGuards: signal.getGuards ?? current.getGuards,
103
103
  cruGuards: signal.cruGuards ?? current.cruGuards,
104
+ createGuards: signal.createGuards ?? current.createGuards,
105
+ updateGuards: signal.updateGuards ?? current.updateGuards,
106
+ removeGuards: signal.removeGuards ?? current.removeGuards,
104
107
  }
105
108
  : signal;
106
109
  }
@@ -353,6 +356,10 @@ export class FetchClient {
353
356
  modelId: `${refName}Id`,
354
357
  lightModel: `light${capRefName}`,
355
358
  };
359
+
360
+ const createGuards = signal.createGuards ?? signal.cruGuards;
361
+ const updateGuards = signal.updateGuards ?? signal.cruGuards;
362
+ const removeGuards = signal.removeGuards ?? signal.cruGuards;
356
363
  const endpoint: { [key: string]: SerializedEndpoint } = {};
357
364
  if (signal.getGuards) {
358
365
  endpoint[names.model] = {
@@ -368,13 +375,15 @@ export class FetchClient {
368
375
  guards: signal.getGuards,
369
376
  };
370
377
  }
371
- if (signal.cruGuards) {
378
+ if (createGuards) {
372
379
  endpoint[names.createModel] = {
373
380
  type: "mutation",
374
381
  args: [{ type: "body", name: "data", refName, modelType: "input" }],
375
382
  returns: { refName, modelType: "full" },
376
- guards: signal.cruGuards,
383
+ guards: createGuards,
377
384
  };
385
+ }
386
+ if (updateGuards) {
378
387
  endpoint[names.updateModel] = {
379
388
  type: "mutation",
380
389
  args: [
@@ -382,13 +391,15 @@ export class FetchClient {
382
391
  { type: "body", name: "data", refName, modelType: "input" },
383
392
  ],
384
393
  returns: { refName, modelType: "full" },
385
- guards: signal.cruGuards,
394
+ guards: updateGuards,
386
395
  };
396
+ }
397
+ if (removeGuards) {
387
398
  endpoint[names.removeModel] = {
388
399
  type: "mutation",
389
400
  args: [{ type: "param", name: names.modelId, refName: "ID" }],
390
401
  returns: { refName, modelType: "full" },
391
- guards: signal.cruGuards,
402
+ guards: removeGuards,
392
403
  };
393
404
  }
394
405
  return endpoint;
@@ -414,7 +425,9 @@ export class FetchClient {
414
425
  this.#setHandlerFactory(key, () => this.#makeHttpFn(key, value, signal.prefix));
415
426
  });
416
427
 
417
- if (signal.cruGuards) {
428
+ const anyCruGuards = signal.cruGuards ?? signal.createGuards ?? signal.updateGuards ?? signal.removeGuards;
429
+ const updateGuards = signal.updateGuards ?? signal.cruGuards;
430
+ if (anyCruGuards) {
418
431
  this.#setHandlerFactory(
419
432
  names.viewModel,
420
433
  () =>
@@ -461,15 +474,17 @@ export class FetchClient {
461
474
  return { refName, [`${refName}Obj`]: modelObj, [`${refName}ViewAt`]: new Date() };
462
475
  }) as FetchHandler,
463
476
  );
464
- this.#setHandlerFactory(
465
- names.mergeModel,
466
- () =>
467
- (async (modelOrId: string | { id: string }, data: UnknownRecord, option?: FetchPolicy) => {
468
- const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
469
- const updateFn = this.#requireHandler(names.updateModel, names.mergeModel);
470
- return await updateFn(id, data, option);
471
- }) as FetchHandler,
472
- );
477
+ if (updateGuards) {
478
+ this.#setHandlerFactory(
479
+ names.mergeModel,
480
+ () =>
481
+ (async (modelOrId: string | { id: string }, data: UnknownRecord, option?: FetchPolicy) => {
482
+ const id = typeof modelOrId === "string" ? modelOrId : modelOrId.id;
483
+ const updateFn = this.#requireHandler(names.updateModel, names.mergeModel);
484
+ return await updateFn(id, data, option);
485
+ }) as FetchHandler,
486
+ );
487
+ }
473
488
  }
474
489
 
475
490
  this.#setHandlerFactory(
@@ -102,6 +102,16 @@ export class FetchSerializer {
102
102
  ...(sliceCls.cruGuards.filter((g) => g.name !== "None").length
103
103
  ? { cruGuards: sliceCls.cruGuards.map((g) => g.name) }
104
104
  : {}),
105
+
106
+ ...(sliceCls.createGuards !== sliceCls.cruGuards && sliceCls.createGuards.filter((g) => g.name !== "None").length
107
+ ? { createGuards: sliceCls.createGuards.map((g) => g.name) }
108
+ : {}),
109
+ ...(sliceCls.updateGuards !== sliceCls.cruGuards && sliceCls.updateGuards.filter((g) => g.name !== "None").length
110
+ ? { updateGuards: sliceCls.updateGuards.map((g) => g.name) }
111
+ : {}),
112
+ ...(sliceCls.removeGuards !== sliceCls.cruGuards && sliceCls.removeGuards.filter((g) => g.name !== "None").length
113
+ ? { removeGuards: sliceCls.removeGuards.map((g) => g.name) }
114
+ : {}),
105
115
  endpoint,
106
116
  };
107
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "2.3.11",
3
+ "version": "2.3.12-rc.1",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -232,14 +232,14 @@ export class SignalResolver {
232
232
  });
233
233
 
234
234
  endpointObj[`create${capitalizedRefName}`] = (builder as any)
235
- .mutation(cnst.full, { guards: sliceCls.cruGuards })
235
+ .mutation(cnst.full, { guards: sliceCls.createGuards })
236
236
  .body("data", cnst.input)
237
237
  .exec(async function (this: any, data: any) {
238
238
  return await this[serviceName].__create(data);
239
239
  });
240
240
 
241
241
  endpointObj[`update${capitalizedRefName}`] = (builder as any)
242
- .mutation(cnst.full, { guards: sliceCls.cruGuards })
242
+ .mutation(cnst.full, { guards: sliceCls.updateGuards })
243
243
  .param(`${refName}Id`, ID)
244
244
  .body("data", cnst.input)
245
245
  .exec(async function (this: any, id: string, data: any) {
@@ -247,7 +247,7 @@ export class SignalResolver {
247
247
  });
248
248
 
249
249
  endpointObj[`remove${capitalizedRefName}`] = (builder as any)
250
- .mutation(cnst.full, { guards: sliceCls.cruGuards })
250
+ .mutation(cnst.full, { guards: sliceCls.removeGuards })
251
251
  .param(`${refName}Id`, ID)
252
252
  .exec(async function (this: any, id: string) {
253
253
  return await this[serviceName].__remove(id);
@@ -99,6 +99,16 @@ export class FetchSerializer {
99
99
  ...(sliceCls.cruGuards.filter((g) => g.name !== "None").length
100
100
  ? { cruGuards: sliceCls.cruGuards.map((g) => g.name) }
101
101
  : {}),
102
+
103
+ ...(sliceCls.createGuards !== sliceCls.cruGuards && sliceCls.createGuards.filter((g) => g.name !== "None").length
104
+ ? { createGuards: sliceCls.createGuards.map((g) => g.name) }
105
+ : {}),
106
+ ...(sliceCls.updateGuards !== sliceCls.cruGuards && sliceCls.updateGuards.filter((g) => g.name !== "None").length
107
+ ? { updateGuards: sliceCls.updateGuards.map((g) => g.name) }
108
+ : {}),
109
+ ...(sliceCls.removeGuards !== sliceCls.cruGuards && sliceCls.removeGuards.filter((g) => g.name !== "None").length
110
+ ? { removeGuards: sliceCls.removeGuards.map((g) => g.name) }
111
+ : {}),
102
112
  endpoint,
103
113
  };
104
114
  }
@@ -341,6 +341,11 @@ export class SignalContext<
341
341
  getEnv() {
342
342
  return this.#env;
343
343
  }
344
+ getArg<T = unknown>(argName: string): T | undefined {
345
+ const index = this.endpointInfo.args.findIndex((arg) => arg.name === argName);
346
+ if (index === -1) return undefined;
347
+ return this.args[index] as T;
348
+ }
344
349
  }
345
350
 
346
351
  export class HttpExecutionContext<Appended = unknown> {
package/signal/slice.ts CHANGED
@@ -35,6 +35,9 @@ export type SliceCls<
35
35
  [SLICE_META]: SliceInfoObj;
36
36
  getGuards: GuardCls[];
37
37
  cruGuards: GuardCls[];
38
+ createGuards: GuardCls[];
39
+ updateGuards: GuardCls[];
40
+ removeGuards: GuardCls[];
38
41
  };
39
42
 
40
43
  interface RootSliceOption {
@@ -42,6 +45,9 @@ interface RootSliceOption {
42
45
  root?: Cls<Guard> | Cls<Guard>[];
43
46
  get?: Cls<Guard> | Cls<Guard>[];
44
47
  cru?: Cls<Guard> | Cls<Guard>[];
48
+ create?: Cls<Guard> | Cls<Guard>[];
49
+ update?: Cls<Guard> | Cls<Guard>[];
50
+ remove?: Cls<Guard> | Cls<Guard>[];
45
51
  };
46
52
  prefix?: string;
47
53
  }
@@ -123,21 +129,14 @@ export function slice<
123
129
  srv.cnst.insight,
124
130
  srv.db.filter,
125
131
  );
126
- const rootGuards = option.guards?.root
127
- ? Array.isArray(option.guards.root)
128
- ? option.guards.root
129
- : [option.guards.root]
130
- : [];
131
- const getGuards = option.guards?.get
132
- ? Array.isArray(option.guards.get)
133
- ? option.guards.get
134
- : [option.guards.get]
135
- : [];
136
- const cruGuards = option.guards?.cru
137
- ? Array.isArray(option.guards.cru)
138
- ? option.guards.cru
139
- : [option.guards.cru]
140
- : [];
132
+ const toGuards = (guard?: Cls<Guard> | Cls<Guard>[]) => (guard ? (Array.isArray(guard) ? guard : [guard]) : []);
133
+ const rootGuards = toGuards(option.guards?.root);
134
+ const getGuards = toGuards(option.guards?.get);
135
+ const cruGuards = toGuards(option.guards?.cru);
136
+
137
+ const createGuards = option.guards?.create ? toGuards(option.guards.create) : cruGuards;
138
+ const updateGuards = option.guards?.update ? toGuards(option.guards.update) : cruGuards;
139
+ const removeGuards = option.guards?.remove ? toGuards(option.guards.remove) : cruGuards;
141
140
  const srvKeys = [
142
141
  ...new Set([...Object.keys(srv.srvMap), ...libSlices.flatMap((libSlice) => Object.keys(libSlice.srv.srvMap))]),
143
142
  ];
@@ -148,6 +147,9 @@ export function slice<
148
147
  static srv = srv;
149
148
  static getGuards = getGuards;
150
149
  static cruGuards = cruGuards;
150
+ static createGuards = createGuards;
151
+ static updateGuards = updateGuards;
152
+ static removeGuards = removeGuards;
151
153
  static [SLICE_META] = Object.assign(
152
154
  {
153
155
  [""]: init({ guards: rootGuards })
package/signal/types.ts CHANGED
@@ -129,6 +129,9 @@ export interface SerializedSignal {
129
129
  filter?: SerializedFilter;
130
130
  getGuards?: string[];
131
131
  cruGuards?: string[];
132
+ createGuards?: string[];
133
+ updateGuards?: string[];
134
+ removeGuards?: string[];
132
135
  }
133
136
 
134
137
  export type SignalType = "restapi" | "websocket";
@@ -48,6 +48,7 @@ export declare class SignalContext<Ctx extends HttpExecutionContext | WebSocketE
48
48
  getWebSocketContext<Appended = unknown>(): WebSocketExecutionContext<Appended>;
49
49
  getRoomId(key: string): string;
50
50
  getEnv(): Env;
51
+ getArg<T = unknown>(argName: string): T | undefined;
51
52
  }
52
53
  export declare class HttpExecutionContext<Appended = unknown> {
53
54
  #private;
@@ -27,12 +27,18 @@ export type SliceCls<SrvModule extends ServiceModel = ServiceModel, SliceInfoObj
27
27
  [SLICE_META]: SliceInfoObj;
28
28
  getGuards: GuardCls[];
29
29
  cruGuards: GuardCls[];
30
+ createGuards: GuardCls[];
31
+ updateGuards: GuardCls[];
32
+ removeGuards: GuardCls[];
30
33
  };
31
34
  interface RootSliceOption {
32
35
  guards?: {
33
36
  root?: Cls<Guard> | Cls<Guard>[];
34
37
  get?: Cls<Guard> | Cls<Guard>[];
35
38
  cru?: Cls<Guard> | Cls<Guard>[];
39
+ create?: Cls<Guard> | Cls<Guard>[];
40
+ update?: Cls<Guard> | Cls<Guard>[];
41
+ remove?: Cls<Guard> | Cls<Guard>[];
36
42
  };
37
43
  prefix?: string;
38
44
  }
@@ -122,6 +122,9 @@ export interface SerializedSignal {
122
122
  filter?: SerializedFilter;
123
123
  getGuards?: string[];
124
124
  cruGuards?: string[];
125
+ createGuards?: string[];
126
+ updateGuards?: string[];
127
+ removeGuards?: string[];
125
128
  }
126
129
  export type SignalType = "restapi" | "websocket";
127
130
  export type WebsocketReqData = {
@@ -1,6 +1,15 @@
1
- import { type FirebaseOptions } from "firebase/app";
2
1
  export type PushNotificationPlatform = "web" | "ios" | "android";
3
2
  export type PushNotificationProvider = "fcm";
3
+ export interface FirebaseOptions {
4
+ apiKey?: string;
5
+ authDomain?: string;
6
+ databaseURL?: string;
7
+ projectId?: string;
8
+ storageBucket?: string;
9
+ messagingSenderId?: string;
10
+ appId?: string;
11
+ measurementId?: string;
12
+ }
4
13
  export interface PushToken {
5
14
  token: string;
6
15
  platform: PushNotificationPlatform;
@@ -2,13 +2,22 @@
2
2
 
3
3
  import { router } from "akanjs/client";
4
4
  import { loadCapacitorDevice, loadCapacitorFcm, loadCapacitorPushNotifications } from "akanjs/client/capacitor";
5
- import { getApps, initializeApp, type FirebaseOptions } from "firebase/app";
6
- import { getMessaging, getToken as getFirebaseToken } from "firebase/messaging";
7
5
  import { useEffect } from "react";
8
6
 
9
7
  export type PushNotificationPlatform = "web" | "ios" | "android";
10
8
  export type PushNotificationProvider = "fcm";
11
9
 
10
+ export interface FirebaseOptions {
11
+ apiKey?: string;
12
+ authDomain?: string;
13
+ databaseURL?: string;
14
+ projectId?: string;
15
+ storageBucket?: string;
16
+ messagingSenderId?: string;
17
+ appId?: string;
18
+ measurementId?: string;
19
+ }
20
+
12
21
  export interface PushToken {
13
22
  token: string;
14
23
  platform: PushNotificationPlatform;
@@ -35,6 +44,9 @@ const getClientEnv = () => globalThis.__AKAN_CLIENT_ENV__;
35
44
 
36
45
  const getFirebaseConfig = () => getClientEnv()?.firebase;
37
46
 
47
+ const firebaseAppPackage = "firebase/app";
48
+ const firebaseMessagingPackage = "firebase/messaging";
49
+
38
50
  const normalizePlatform = (platform: string): PushNotificationPlatform | null => {
39
51
  if (platform === "web" || platform === "ios" || platform === "android") return platform;
40
52
  return null;
@@ -84,9 +96,18 @@ const getNativeToken = async (options?: { retries?: number }): Promise<PushToken
84
96
  const getWebToken = async (): Promise<PushToken | undefined> => {
85
97
  if (!isWebRuntime() || !("serviceWorker" in navigator)) return undefined;
86
98
  const firebaseConfig = getFirebaseConfig();
87
- if (!firebaseConfig?.apiKey || !firebaseConfig.projectId || !firebaseConfig.messagingSenderId || !firebaseConfig.appId) {
99
+ if (
100
+ !firebaseConfig?.apiKey ||
101
+ !firebaseConfig.projectId ||
102
+ !firebaseConfig.messagingSenderId ||
103
+ !firebaseConfig.appId
104
+ ) {
88
105
  return undefined;
89
106
  }
107
+ const [{ getApps, initializeApp }, { getToken: getFirebaseToken, getMessaging }] = await Promise.all([
108
+ null as unknown as typeof import("firebase/app"), //! temporary disabled
109
+ null as unknown as typeof import("firebase/messaging"), //@ temporary disabled
110
+ ]);
90
111
  const firebase = getApps()[0] ?? initializeApp(firebaseConfig);
91
112
  const messaging = getMessaging(firebase);
92
113
  const serviceWorkerRegistration = await navigator.serviceWorker.register("/firebase-messaging-sw.js");