@akanjs/signal 0.0.4

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.
@@ -0,0 +1,2 @@
1
+ import { type Type } from "@akanjs/base";
2
+ export declare const immerify: <T extends object | object[]>(modelRef: Type, objOrArr: T) => T;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var immerify_exports = {};
19
+ __export(immerify_exports, {
20
+ immerify: () => immerify
21
+ });
22
+ module.exports = __toCommonJS(immerify_exports);
23
+ var import_constant = require("@akanjs/constant");
24
+ var import_immer = require("immer");
25
+ const immerify = (modelRef, objOrArr) => {
26
+ if (Array.isArray(objOrArr))
27
+ return objOrArr.map((val) => immerify(modelRef, val));
28
+ const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
29
+ const immeredObj = Object.assign({}, objOrArr, { [import_immer.immerable]: true });
30
+ fieldMetas.forEach((fieldMeta) => {
31
+ if (fieldMeta.isScalar && fieldMeta.isClass && !!objOrArr[fieldMeta.key])
32
+ immeredObj[fieldMeta.key] = immerify(fieldMeta.modelRef, objOrArr[fieldMeta.key]);
33
+ });
34
+ return immeredObj;
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ immerify
39
+ });
package/src/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { type Client, client } from "./client";
2
+ export { immerify } from "./immerify";
3
+ export * from "./gql";
4
+ export * from "./signalDecorators";
5
+ export * from "./doc";
package/src/index.js ADDED
@@ -0,0 +1,37 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var src_exports = {};
20
+ __export(src_exports, {
21
+ client: () => import_client.client,
22
+ immerify: () => import_immerify.immerify
23
+ });
24
+ module.exports = __toCommonJS(src_exports);
25
+ var import_client = require("./client");
26
+ var import_immerify = require("./immerify");
27
+ __reExport(src_exports, require("./gql"), module.exports);
28
+ __reExport(src_exports, require("./signalDecorators"), module.exports);
29
+ __reExport(src_exports, require("./doc"), module.exports);
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ client,
33
+ immerify,
34
+ ...require("./gql"),
35
+ ...require("./signalDecorators"),
36
+ ...require("./doc")
37
+ });
@@ -0,0 +1,295 @@
1
+ import "reflect-metadata";
2
+ import { BaseObject, Dayjs, Enum, Environment, SingleFieldType, Type } from "@akanjs/base";
3
+ import { ConstantModel, DocumentModel, FilterType, GetActionObject, ReturnType, SortOf } from "@akanjs/constant";
4
+ import type { Job as BullJob } from "bull";
5
+ import type { Request as ExpressRequest, Response as ExpressResponse } from "express";
6
+ import type { Socket } from "socket.io";
7
+ export declare const ssoTypes: readonly ["github", "google", "facebook", "apple", "naver", "kakao"];
8
+ export type SSOType = (typeof ssoTypes)[number];
9
+ export declare class SignalStorage {
10
+ }
11
+ export declare const getAllSignalRefs: () => Type[];
12
+ export declare const getSignalRefsOnStorage: (refName: string) => Type[];
13
+ export type Resolve<T> = T;
14
+ export declare const resolve: <T>(data: any) => Resolve<T>;
15
+ export declare const emit: <T>(data: any) => Resolve<T> & {
16
+ __Returns__: "Emit";
17
+ };
18
+ export declare const done: <T>(data: any) => Resolve<T> & {
19
+ __Returns__: "Done";
20
+ };
21
+ export declare const subscribe: <T>() => Resolve<T> & {
22
+ __Returns__: "Subscribe";
23
+ };
24
+ export interface SignalOption<Response = any> {
25
+ nullable?: boolean;
26
+ name?: string;
27
+ default?: boolean;
28
+ path?: string;
29
+ onlyFor?: "graphql" | "restapi";
30
+ sso?: SSOType;
31
+ serverType?: "federation" | "batch" | "all";
32
+ timeout?: number;
33
+ partial?: (keyof Response)[] | readonly (keyof Response)[];
34
+ cache?: number;
35
+ }
36
+ export interface ResolveFieldMeta {
37
+ returns: ReturnType;
38
+ argsOption: ArgsOption;
39
+ key: string;
40
+ descriptor: PropertyDescriptor;
41
+ }
42
+ export declare const signalTypes: readonly ["graphql", "restapi"];
43
+ export type SignalType = (typeof signalTypes)[number];
44
+ export declare const endpointTypes: readonly ["Query", "Mutation", "Message", "Pubsub", "Process"];
45
+ export type EndpointType = (typeof endpointTypes)[number];
46
+ export declare const guardTypes: readonly ["Public", "None", "User", "Admin", "SuperAdmin", "Every", "Owner"];
47
+ export type GuardType = (typeof guardTypes)[number];
48
+ export declare const roleTypes: readonly ["Public", "User", "Admin", "SuperAdmin"];
49
+ export type RoleType = (typeof roleTypes)[number];
50
+ export declare const argTypes: readonly ["Body", "Param", "Query", "Upload", "Msg", "Room"];
51
+ export type ArgType = (typeof argTypes)[number];
52
+ export declare const internalArgTypes: readonly ["Account", "Me", "Self", "UserIp", "Access", "Parent", "Req", "Res", "Ws", "Job"];
53
+ export type InternalArgType = (typeof internalArgTypes)[number];
54
+ export interface GqlMeta {
55
+ returns: (of?: any) => Type;
56
+ signalOption: SignalOption;
57
+ key: string;
58
+ descriptor: PropertyDescriptor;
59
+ guards: GuardType[];
60
+ type: EndpointType;
61
+ }
62
+ export interface ArgsOption {
63
+ nullable?: boolean;
64
+ example?: string | number | boolean | Dayjs;
65
+ enum?: Enum<string | number>;
66
+ }
67
+ export interface ArgMeta {
68
+ name: string;
69
+ returns: ReturnType;
70
+ argsOption: ArgsOption;
71
+ key: string;
72
+ idx: number;
73
+ type: ArgType;
74
+ }
75
+ export interface InternalArgMeta {
76
+ key: string;
77
+ idx: number;
78
+ type: InternalArgType;
79
+ option?: {
80
+ nullable?: boolean;
81
+ };
82
+ }
83
+ export interface SliceMeta {
84
+ refName: string;
85
+ sliceName: string;
86
+ argLength: number;
87
+ defaultArgs: any[];
88
+ }
89
+ export interface SignalMeta {
90
+ refName: string;
91
+ slices: SliceMeta[];
92
+ returns?: (of?: any) => Type;
93
+ prefix?: string;
94
+ }
95
+ interface SignalDecoratorInput {
96
+ name: string;
97
+ prefix?: string;
98
+ }
99
+ export declare function Signal(returnsOrObj: (() => Type) | SignalDecoratorInput): (target: Type) => void;
100
+ export declare const createArgMetaDecorator: (type: InternalArgType) => (option?: {
101
+ nullable?: boolean;
102
+ }) => (prototype: object, key: string, idx: number) => void;
103
+ export declare const Account: (option?: {
104
+ nullable?: boolean;
105
+ }) => (prototype: object, key: string, idx: number) => void;
106
+ export type Account<AddData = unknown> = {
107
+ __InternalArg__: "Account";
108
+ self?: Self;
109
+ me?: Me;
110
+ appName: string;
111
+ environment: Environment;
112
+ } & AddData;
113
+ export declare const defaultAccount: Account;
114
+ export declare const Self: (option?: {
115
+ nullable?: boolean;
116
+ }) => (prototype: object, key: string, idx: number) => void;
117
+ export interface Self {
118
+ __InternalArg__: "Self";
119
+ id: string;
120
+ nickname: string;
121
+ roles: string[];
122
+ image: {
123
+ url: string;
124
+ imageSize: [number, number];
125
+ } | null;
126
+ profileStatus: "active" | "prepare" | "applied" | "approved" | "reapplied" | "featured" | "reserved" | "rejected";
127
+ status: "prepare" | "active" | "restricted" | "dormant";
128
+ removedAt: Dayjs | null;
129
+ }
130
+ export declare const Me: (option?: {
131
+ nullable?: boolean;
132
+ }) => (prototype: object, key: string, idx: number) => void;
133
+ export interface Me {
134
+ __InternalArg__: "Me";
135
+ id: string;
136
+ accountId: string;
137
+ roles: string[];
138
+ status: "active";
139
+ removedAt: Dayjs | null;
140
+ }
141
+ export declare const UserIp: (option?: {
142
+ nullable?: boolean;
143
+ }) => (prototype: object, key: string, idx: number) => void;
144
+ export interface UserIp {
145
+ ip: string;
146
+ __InternalArg__: "UserIp";
147
+ }
148
+ export declare const Access: (option?: {
149
+ nullable?: boolean;
150
+ }) => (prototype: object, key: string, idx: number) => void;
151
+ export interface Access {
152
+ __InternalArg__: "Access";
153
+ period: number;
154
+ countryCode?: string;
155
+ countryName?: string;
156
+ city?: string;
157
+ postal?: number;
158
+ location?: {
159
+ type: "Point";
160
+ coordinates: [number, number];
161
+ };
162
+ ipv4?: string;
163
+ state?: string;
164
+ userAgent?: string;
165
+ at: Dayjs;
166
+ }
167
+ export declare const Req: (option?: {
168
+ nullable?: boolean;
169
+ }) => (prototype: object, key: string, idx: number) => void;
170
+ export type Req = {
171
+ __InternalArg__: "Req";
172
+ account: Account;
173
+ user: any;
174
+ } & ExpressRequest;
175
+ export declare const Res: (option?: {
176
+ nullable?: boolean;
177
+ }) => (prototype: object, key: string, idx: number) => void;
178
+ export type Res = {
179
+ __InternalArg__: "Res";
180
+ } & ExpressResponse;
181
+ export declare const Ws: (option?: {
182
+ nullable?: boolean;
183
+ }) => (prototype: object, key: string, idx: number) => void;
184
+ export type Ws = {
185
+ __InternalArg__: "Ws";
186
+ } & {
187
+ socket: Socket;
188
+ subscribe: boolean;
189
+ onSubscribe: (handler: () => void | Promise<void>) => void;
190
+ onUnsubscribe: (handler: () => void | Promise<void>) => void;
191
+ onDisconnect: (handler: () => void | Promise<void>) => void;
192
+ };
193
+ export declare const Job: (option?: {
194
+ nullable?: boolean;
195
+ }) => (prototype: object, key: string, idx: number) => void;
196
+ export type Job = {
197
+ __InternalArg__: "Job";
198
+ } & BullJob;
199
+ type Guard = <Response extends SingleFieldType>(returns: ReturnType<Response>, signalOption?: SignalOption<UnType<Response>>, guards?: GuardType[]) => MethodDecorator;
200
+ export declare const Query: {
201
+ Public: Guard;
202
+ Every: Guard;
203
+ Admin: Guard;
204
+ User: Guard;
205
+ SuperAdmin: Guard;
206
+ None: Guard;
207
+ Owner: Guard;
208
+ };
209
+ export declare const Mutation: {
210
+ Public: Guard;
211
+ Every: Guard;
212
+ Admin: Guard;
213
+ User: Guard;
214
+ SuperAdmin: Guard;
215
+ None: Guard;
216
+ Owner: Guard;
217
+ };
218
+ export declare const Message: {
219
+ Public: Guard;
220
+ Every: Guard;
221
+ Admin: Guard;
222
+ User: Guard;
223
+ SuperAdmin: Guard;
224
+ None: Guard;
225
+ Owner: Guard;
226
+ };
227
+ export declare const Pubsub: {
228
+ Public: Guard;
229
+ Every: Guard;
230
+ Admin: Guard;
231
+ User: Guard;
232
+ SuperAdmin: Guard;
233
+ None: Guard;
234
+ Owner: Guard;
235
+ };
236
+ export declare const Process: {
237
+ Federation: Guard;
238
+ Batch: Guard;
239
+ All: Guard;
240
+ };
241
+ export declare function ResolveField(returns: ReturnType, argsOption?: ArgsOption): (target: any, key: string, descriptor: PropertyDescriptor) => void;
242
+ export declare const Arg: {
243
+ Body: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
244
+ Param: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
245
+ Query: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
246
+ Upload: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
247
+ Msg: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
248
+ Room: (name: string, returns: ReturnType, argsOption?: ArgsOption) => (prototype: object, key: string, idx: number) => void;
249
+ };
250
+ export declare function Parent(): (prototype: object, key: string, idx: number) => void;
251
+ export declare function LogSignal<Srv>(srv: Srv): Type<{ [K in keyof Srv as K extends string ? Uncapitalize<K> : never]: Srv[K]; }>;
252
+ type UnType<Class> = Class extends Type<infer T> ? T : never;
253
+ export type DefaultSignal<T extends string, Input, Full, Light, Insight, Filter extends FilterType> = DefaultSignalWithQuerySort<T, Input, Full, Light, Insight, GetActionObject<Filter>, SortOf<Filter>>;
254
+ type DefaultSignalWithQuerySort<T extends string, Input, Full, Light, Insight, Query, Sort> = {
255
+ [K in Uncapitalize<T>]: (id: string) => Promise<Full>;
256
+ } & {
257
+ [K in `light${Capitalize<T>}`]: (id: string) => Promise<Light>;
258
+ } & {
259
+ [K in `${Uncapitalize<T>}List`]: (...args: [query: Query, skip: number | null, limit: number | null, sort: Sort | null]) => Promise<Full[]>;
260
+ } & {
261
+ [K in `${Uncapitalize<T>}Insight`]: (query: Query) => Promise<Insight>;
262
+ } & {
263
+ [K in `${Uncapitalize<T>}Exists`]: (query: Query) => Promise<boolean>;
264
+ } & {
265
+ [K in `create${Capitalize<T>}`]: (data: DocumentModel<Input>, account: Account) => Promise<Full>;
266
+ } & {
267
+ [K in `update${Capitalize<T>}`]: (id: string, data: DocumentModel<Input>, account: Account) => Promise<Full>;
268
+ } & {
269
+ [K in `remove${Capitalize<T>}`]: (id: string, account: Account) => Promise<Full>;
270
+ };
271
+ export declare function DbSignal<Srv>(constant: ConstantModel<string, any, BaseObject & {
272
+ status: string;
273
+ }, BaseObject, {
274
+ count: number;
275
+ }, any>, srv: Srv, option: {
276
+ guards: {
277
+ get: Guard;
278
+ cru: Guard;
279
+ };
280
+ omit?: ("get" | "list" | "insight" | "exist" | "create" | "update" | "remove")[];
281
+ }): Type<{ [K in keyof Srv as K extends string ? Uncapitalize<K> : never]: Srv[K]; }>;
282
+ export declare const getSigMeta: (sigRef: Type) => SignalMeta;
283
+ export declare const getGqlMeta: (sigRef: Type, key: string) => GqlMeta;
284
+ export declare const getGqlMetaMapOnPrototype: (prototype: object) => Map<string, GqlMeta>;
285
+ export declare const getGqlMetas: (sigRef: Type) => GqlMeta[];
286
+ export declare const setGqlMetaMapOnPrototype: (prototype: object, gqlMetaMap: Map<string, GqlMeta>) => void;
287
+ export declare const getArgMetas: (sigRef: Type, key: string) => [ArgMeta[], InternalArgMeta[]];
288
+ export declare const setArgMetas: (sigRef: Type, key: string, argMetas: ArgMeta[], internalArgMetas: InternalArgMeta[]) => void;
289
+ export declare const getResolveFieldMetas: (sigRef: Type) => ResolveFieldMeta[];
290
+ export declare const getControllerPrefix: (sigMeta: SignalMeta) => string | undefined;
291
+ export declare const getControllerPath: (gqlMeta: GqlMeta, paramArgMetas: ArgMeta[]) => string;
292
+ export declare const copySignal: (sigRef: Type) => {
293
+ new (): {};
294
+ };
295
+ export {};