akanjs 2.3.11 → 2.3.12-rc.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/fetch/client/fetchClient.ts +29 -14
- package/fetch/serializer/fetch.serializer.ts +10 -0
- package/package.json +1 -1
- package/server/resolver/signal.resolver.ts +3 -3
- package/signal/serializer/fetch.serializer.ts +10 -0
- package/signal/signalContext.ts +5 -0
- package/signal/slice.ts +17 -15
- package/signal/types.ts +3 -0
- package/types/signal/signalContext.d.ts +1 -0
- package/types/signal/slice.d.ts +6 -0
- package/types/signal/types.d.ts +3 -0
- package/types/webkit/usePushNotification.d.ts +10 -1
- package/webkit/usePushNotification.tsx +21 -3
|
@@ -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 (
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
(
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
|
@@ -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.
|
|
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.
|
|
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.
|
|
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
|
}
|
package/signal/signalContext.ts
CHANGED
|
@@ -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
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
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;
|
package/types/signal/slice.d.ts
CHANGED
|
@@ -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
|
}
|
package/types/signal/types.d.ts
CHANGED
|
@@ -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;
|
|
@@ -84,9 +93,18 @@ const getNativeToken = async (options?: { retries?: number }): Promise<PushToken
|
|
|
84
93
|
const getWebToken = async (): Promise<PushToken | undefined> => {
|
|
85
94
|
if (!isWebRuntime() || !("serviceWorker" in navigator)) return undefined;
|
|
86
95
|
const firebaseConfig = getFirebaseConfig();
|
|
87
|
-
if (
|
|
96
|
+
if (
|
|
97
|
+
!firebaseConfig?.apiKey ||
|
|
98
|
+
!firebaseConfig.projectId ||
|
|
99
|
+
!firebaseConfig.messagingSenderId ||
|
|
100
|
+
!firebaseConfig.appId
|
|
101
|
+
) {
|
|
88
102
|
return undefined;
|
|
89
103
|
}
|
|
104
|
+
const [{ getApps, initializeApp }, { getToken: getFirebaseToken, getMessaging }] = await Promise.all([
|
|
105
|
+
import("firebase/app"),
|
|
106
|
+
import("firebase/messaging"),
|
|
107
|
+
]);
|
|
90
108
|
const firebase = getApps()[0] ?? initializeApp(firebaseConfig);
|
|
91
109
|
const messaging = getMessaging(firebase);
|
|
92
110
|
const serviceWorkerRegistration = await navigator.serviceWorker.register("/firebase-messaging-sw.js");
|