@akanjs/base 0.0.1 → 0.0.2
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/index.js +1 -0
- package/package.json +17 -3
- package/src/base.d.ts +46 -0
- package/src/base.js +159 -0
- package/src/baseEnv.d.ts +46 -0
- package/src/baseEnv.js +61 -0
- package/src/index.js +4 -0
- package/src/scalar.d.ts +46 -0
- package/src/scalar.js +105 -0
- package/src/types.d.ts +40 -0
- package/src/types.js +0 -0
- package/project.json +0 -23
- package/src/base.ts +0 -145
- package/src/baseEnv.ts +0 -110
- package/src/scalar.ts +0 -104
- package/src/types.ts +0 -50
- package/tsconfig.json +0 -13
- package/tsconfig.spec.json +0 -7
- /package/{index.ts → index.d.ts} +0 -0
- /package/src/{index.ts → index.d.ts} +0 -0
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src";
|
package/package.json
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/base",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "module"
|
|
5
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/akan-team/akanjs.git",
|
|
11
|
+
"directory": "pkgs/@akanjs/base"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"dayjs": "1.11.13",
|
|
15
|
+
"tunnel-ssh": "5.2.0"
|
|
16
|
+
},
|
|
17
|
+
"module": "./index.js",
|
|
18
|
+
"main": "./index.js"
|
|
19
|
+
}
|
package/src/base.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare class Enum<T> {
|
|
2
|
+
readonly values: T[];
|
|
3
|
+
readonly value: T;
|
|
4
|
+
readonly valueMap: Map<T, number>;
|
|
5
|
+
constructor(values: T[]);
|
|
6
|
+
has(value: T): boolean;
|
|
7
|
+
indexOf(value: T): number;
|
|
8
|
+
find(callback: (value: T, index: number, array: T[]) => boolean): T;
|
|
9
|
+
findIndex(callback: (value: T, index: number, array: T[]) => boolean): number;
|
|
10
|
+
filter(callback: (value: T, index: number, array: T[]) => boolean): T[];
|
|
11
|
+
map<R>(callback: (value: T, index: number, array: T[]) => R): R[];
|
|
12
|
+
forEach(callback: (value: T, index: number, array: T[]) => void): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const enumOf: <T>(values: T[]) => Enum<T>;
|
|
15
|
+
export type EnumType<E> = E extends Enum<infer T> ? T : never;
|
|
16
|
+
export declare class DataList<Light extends {
|
|
17
|
+
id: string;
|
|
18
|
+
}> {
|
|
19
|
+
#private;
|
|
20
|
+
length: number;
|
|
21
|
+
values: Light[];
|
|
22
|
+
constructor(data?: Light[] | DataList<Light>);
|
|
23
|
+
indexOf(id: string): number;
|
|
24
|
+
set(value: Light): this;
|
|
25
|
+
delete(id: string): this;
|
|
26
|
+
get(id: string): Light | undefined;
|
|
27
|
+
at(idx: number): Light | undefined;
|
|
28
|
+
pickAt(idx: number): Light;
|
|
29
|
+
pick(id: string): Light;
|
|
30
|
+
has(id: string): boolean;
|
|
31
|
+
find(fn: (value: Light, idx: number) => boolean): Light | undefined;
|
|
32
|
+
findIndex(fn: (value: Light, idx: number) => boolean): number;
|
|
33
|
+
some(fn: (value: Light, idx: number) => boolean): boolean;
|
|
34
|
+
every(fn: (value: Light, idx: number) => boolean): boolean;
|
|
35
|
+
forEach(fn: (value: Light, idx: number) => void): void;
|
|
36
|
+
map<T>(fn: (value: Light, idx: number) => T): T[];
|
|
37
|
+
flatMap<T>(fn: (value: Light, idx: number, array: Light[]) => T | readonly T[]): T[];
|
|
38
|
+
sort(fn: (a: Light, b: Light) => number): DataList<Light>;
|
|
39
|
+
filter(fn: (value: Light, idx: number) => boolean): DataList<Light>;
|
|
40
|
+
reduce<T>(fn: (acc: T, value: Light, idx: number) => T, initialValue: T): T;
|
|
41
|
+
slice(start: number, end?: number): DataList<Light>;
|
|
42
|
+
save(): DataList<Light>;
|
|
43
|
+
[Symbol.iterator](): ArrayIterator<Light>;
|
|
44
|
+
}
|
|
45
|
+
export declare const version = "0.9.0";
|
|
46
|
+
export declare const logo = "\n _ _ _ \n / \\ | | ____ _ _ __ (_)___ \n / _ \\ | |/ / _' | '_ \\ | / __|\n / ___ \\| < (_| | | | |_ | \\__ \\\n /_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/\n |__/ ver 0.9.0\n? See more details on docs https://www.akanjs.com/docs\n\u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs\n\n";
|
package/src/base.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
class Enum {
|
|
2
|
+
constructor(values) {
|
|
3
|
+
this.values = values;
|
|
4
|
+
this.valueMap = new Map(values.map((value, idx) => [value, idx]));
|
|
5
|
+
}
|
|
6
|
+
value;
|
|
7
|
+
// for type
|
|
8
|
+
valueMap;
|
|
9
|
+
has(value) {
|
|
10
|
+
return this.valueMap.has(value);
|
|
11
|
+
}
|
|
12
|
+
indexOf(value) {
|
|
13
|
+
const idx = this.valueMap.get(value);
|
|
14
|
+
if (idx === void 0)
|
|
15
|
+
throw new Error(`Value ${value} is not in enum`);
|
|
16
|
+
return idx;
|
|
17
|
+
}
|
|
18
|
+
find(callback) {
|
|
19
|
+
const val = this.values.find(callback);
|
|
20
|
+
if (val === void 0)
|
|
21
|
+
throw new Error(`Value not found in enum`);
|
|
22
|
+
return val;
|
|
23
|
+
}
|
|
24
|
+
findIndex(callback) {
|
|
25
|
+
const idx = this.values.findIndex(callback);
|
|
26
|
+
if (idx === -1)
|
|
27
|
+
throw new Error(`Value not found in enum`);
|
|
28
|
+
return idx;
|
|
29
|
+
}
|
|
30
|
+
filter(callback) {
|
|
31
|
+
return this.values.filter(callback);
|
|
32
|
+
}
|
|
33
|
+
map(callback) {
|
|
34
|
+
return this.values.map(callback);
|
|
35
|
+
}
|
|
36
|
+
forEach(callback) {
|
|
37
|
+
this.values.forEach(callback);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const enumOf = (values) => new Enum(values);
|
|
41
|
+
class DataList {
|
|
42
|
+
// [immerable] = true;
|
|
43
|
+
#idMap;
|
|
44
|
+
length;
|
|
45
|
+
values;
|
|
46
|
+
constructor(data = []) {
|
|
47
|
+
this.values = Array.isArray(data) ? [...data] : [...data.values];
|
|
48
|
+
this.#idMap = new Map(this.values.map((value, idx) => [value.id, idx]));
|
|
49
|
+
this.length = this.values.length;
|
|
50
|
+
}
|
|
51
|
+
indexOf(id) {
|
|
52
|
+
const idx = this.#idMap.get(id);
|
|
53
|
+
if (idx === void 0)
|
|
54
|
+
throw new Error(`Value ${id} is not in list`);
|
|
55
|
+
return idx;
|
|
56
|
+
}
|
|
57
|
+
set(value) {
|
|
58
|
+
const idx = this.#idMap.get(value.id);
|
|
59
|
+
if (idx !== void 0)
|
|
60
|
+
this.values = [...this.values.slice(0, idx), value, ...this.values.slice(idx + 1)];
|
|
61
|
+
else {
|
|
62
|
+
this.#idMap.set(value.id, this.length);
|
|
63
|
+
this.values = [...this.values, value];
|
|
64
|
+
this.length++;
|
|
65
|
+
}
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
delete(id) {
|
|
69
|
+
const idx = this.#idMap.get(id);
|
|
70
|
+
if (idx === void 0)
|
|
71
|
+
return this;
|
|
72
|
+
this.#idMap.delete(id);
|
|
73
|
+
this.values.splice(idx, 1);
|
|
74
|
+
this.values.slice(idx).forEach((value, i) => this.#idMap.set(value.id, i + idx));
|
|
75
|
+
this.length--;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
get(id) {
|
|
79
|
+
const idx = this.#idMap.get(id);
|
|
80
|
+
if (idx === void 0)
|
|
81
|
+
return void 0;
|
|
82
|
+
return this.values[idx];
|
|
83
|
+
}
|
|
84
|
+
at(idx) {
|
|
85
|
+
return this.values.at(idx);
|
|
86
|
+
}
|
|
87
|
+
pickAt(idx) {
|
|
88
|
+
const value = this.values.at(idx);
|
|
89
|
+
if (value === void 0)
|
|
90
|
+
throw new Error(`Value at ${idx} is undefined`);
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
pick(id) {
|
|
94
|
+
return this.values[this.indexOf(id)];
|
|
95
|
+
}
|
|
96
|
+
has(id) {
|
|
97
|
+
return this.#idMap.has(id);
|
|
98
|
+
}
|
|
99
|
+
find(fn) {
|
|
100
|
+
const val = this.values.find(fn);
|
|
101
|
+
return val;
|
|
102
|
+
}
|
|
103
|
+
findIndex(fn) {
|
|
104
|
+
const val = this.values.findIndex(fn);
|
|
105
|
+
return val;
|
|
106
|
+
}
|
|
107
|
+
some(fn) {
|
|
108
|
+
return this.values.some(fn);
|
|
109
|
+
}
|
|
110
|
+
every(fn) {
|
|
111
|
+
return this.values.every(fn);
|
|
112
|
+
}
|
|
113
|
+
forEach(fn) {
|
|
114
|
+
this.values.forEach(fn);
|
|
115
|
+
}
|
|
116
|
+
map(fn) {
|
|
117
|
+
return this.values.map(fn);
|
|
118
|
+
}
|
|
119
|
+
flatMap(fn) {
|
|
120
|
+
return this.values.flatMap(fn);
|
|
121
|
+
}
|
|
122
|
+
sort(fn) {
|
|
123
|
+
return new DataList(this.values.sort(fn));
|
|
124
|
+
}
|
|
125
|
+
filter(fn) {
|
|
126
|
+
return new DataList(this.values.filter(fn));
|
|
127
|
+
}
|
|
128
|
+
reduce(fn, initialValue) {
|
|
129
|
+
return this.values.reduce(fn, initialValue);
|
|
130
|
+
}
|
|
131
|
+
slice(start, end = this.length) {
|
|
132
|
+
return new DataList(this.values.slice(start, end));
|
|
133
|
+
}
|
|
134
|
+
save() {
|
|
135
|
+
return new DataList(this);
|
|
136
|
+
}
|
|
137
|
+
[Symbol.iterator]() {
|
|
138
|
+
return this.values[Symbol.iterator]();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const version = "0.9.0";
|
|
142
|
+
const logo = `
|
|
143
|
+
_ _ _
|
|
144
|
+
/ \\ | | ____ _ _ __ (_)___
|
|
145
|
+
/ _ \\ | |/ / _' | '_ \\ | / __|
|
|
146
|
+
/ ___ \\| < (_| | | | |_ | \\__ \\
|
|
147
|
+
/_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
|
|
148
|
+
|__/ ver ${version}
|
|
149
|
+
? See more details on docs https://www.akanjs.com/docs
|
|
150
|
+
\u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
|
|
151
|
+
|
|
152
|
+
`;
|
|
153
|
+
export {
|
|
154
|
+
DataList,
|
|
155
|
+
Enum,
|
|
156
|
+
enumOf,
|
|
157
|
+
logo,
|
|
158
|
+
version
|
|
159
|
+
};
|
package/src/baseEnv.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SshOptions } from "tunnel-ssh";
|
|
2
|
+
export type Environment = "testing" | "debug" | "develop" | "main";
|
|
3
|
+
export interface BaseEnv {
|
|
4
|
+
repoName: string;
|
|
5
|
+
serveDomain: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
environment: Environment;
|
|
8
|
+
operationType: "server" | "client";
|
|
9
|
+
operationMode: "local" | "edge" | "cloud" | "module";
|
|
10
|
+
networkType: "mainnet" | "testnet" | "debugnet";
|
|
11
|
+
}
|
|
12
|
+
export type BackendEnv = BaseEnv & {
|
|
13
|
+
hostname: string | null;
|
|
14
|
+
appCode: number;
|
|
15
|
+
mongo: {
|
|
16
|
+
username?: string;
|
|
17
|
+
password?: string;
|
|
18
|
+
sshOptions?: SshOptions;
|
|
19
|
+
};
|
|
20
|
+
redis?: {
|
|
21
|
+
sshOptions?: SshOptions;
|
|
22
|
+
};
|
|
23
|
+
port?: number;
|
|
24
|
+
mongoUri?: string;
|
|
25
|
+
redisUri?: string;
|
|
26
|
+
meiliUri?: string;
|
|
27
|
+
onCleanup?: () => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
export declare const baseEnv: BaseEnv;
|
|
30
|
+
export type BaseClientEnv = BaseEnv & {
|
|
31
|
+
side: "server" | "client";
|
|
32
|
+
renderMode: "ssr" | "csr";
|
|
33
|
+
websocket: boolean;
|
|
34
|
+
clientHost: string;
|
|
35
|
+
clientPort: number;
|
|
36
|
+
clientHttpProtocol: "http:" | "https:";
|
|
37
|
+
clientHttpUri: string;
|
|
38
|
+
serverHost: string;
|
|
39
|
+
serverPort: number;
|
|
40
|
+
serverHttpProtocol: "http:" | "https:";
|
|
41
|
+
serverHttpUri: string;
|
|
42
|
+
serverGraphqlUri: string;
|
|
43
|
+
serverWsProtocol: "ws:" | "wss:";
|
|
44
|
+
serverWsUri: string;
|
|
45
|
+
};
|
|
46
|
+
export declare const baseClientEnv: BaseClientEnv;
|
package/src/baseEnv.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
|
|
2
|
+
const appName = process.env.NEXT_PUBLIC_APP_NAME ?? process.env.NX_TASK_TARGET_PROJECT ?? "unknown";
|
|
3
|
+
const repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
|
|
4
|
+
const serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
|
|
5
|
+
if (appName === "unknown")
|
|
6
|
+
throw new Error("environment variable NEXT_PUBLIC_APP_NAME or NX_TASK_TARGET_PROJECT is required");
|
|
7
|
+
if (repoName === "unknown")
|
|
8
|
+
throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
|
|
9
|
+
if (serveDomain === "unknown")
|
|
10
|
+
throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
|
|
11
|
+
const environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
12
|
+
const operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
|
|
13
|
+
const operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
|
|
14
|
+
const networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
|
|
15
|
+
const baseEnv = {
|
|
16
|
+
repoName,
|
|
17
|
+
serveDomain,
|
|
18
|
+
appName,
|
|
19
|
+
environment,
|
|
20
|
+
operationType,
|
|
21
|
+
operationMode,
|
|
22
|
+
networkType
|
|
23
|
+
};
|
|
24
|
+
const side = typeof window === "undefined" ? "server" : "client";
|
|
25
|
+
const renderMode = process.env.RENDER_ENV ?? "ssr";
|
|
26
|
+
const clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
|
|
27
|
+
const clientPort = parseInt(
|
|
28
|
+
process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
|
|
29
|
+
);
|
|
30
|
+
const clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
|
|
31
|
+
const clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
|
|
32
|
+
const serverHost = process.env.SERVER_HOST ?? (operationMode === "local" ? typeof window === "undefined" ? "localhost" : window.location.host.split(":")[0] : renderMode === "csr" ? `${appName}-${environment}.${serveDomain}` : side === "client" ? window.location.host.split(":")[0] : operationMode === "cloud" ? `backend-svc.${appName}-${environment}.svc.cluster.local` : "localhost");
|
|
33
|
+
const serverPort = parseInt(
|
|
34
|
+
process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
|
|
35
|
+
);
|
|
36
|
+
const serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
|
|
37
|
+
const serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
|
|
38
|
+
const serverGraphqlUri = `${serverHttpUri}/graphql`;
|
|
39
|
+
const serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
|
|
40
|
+
const serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
|
|
41
|
+
const baseClientEnv = {
|
|
42
|
+
...baseEnv,
|
|
43
|
+
side,
|
|
44
|
+
renderMode,
|
|
45
|
+
websocket: true,
|
|
46
|
+
clientHost,
|
|
47
|
+
clientPort,
|
|
48
|
+
clientHttpProtocol,
|
|
49
|
+
clientHttpUri,
|
|
50
|
+
serverHost,
|
|
51
|
+
serverPort,
|
|
52
|
+
serverHttpProtocol,
|
|
53
|
+
serverHttpUri,
|
|
54
|
+
serverGraphqlUri,
|
|
55
|
+
serverWsProtocol,
|
|
56
|
+
serverWsUri
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
baseClientEnv,
|
|
60
|
+
baseEnv
|
|
61
|
+
};
|
package/src/index.js
ADDED
package/src/scalar.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import dayjsLib, { Dayjs } from "dayjs";
|
|
2
|
+
import type { ReadStream } from "fs";
|
|
3
|
+
import type { Readable } from "stream";
|
|
4
|
+
import type { GraphQLJSON, GraphQLUpload, Type } from "./types";
|
|
5
|
+
export { Dayjs };
|
|
6
|
+
export declare const dayjs: typeof dayjsLib;
|
|
7
|
+
export declare class BaseObject {
|
|
8
|
+
id: string;
|
|
9
|
+
createdAt: Dayjs;
|
|
10
|
+
updatedAt: Dayjs;
|
|
11
|
+
removedAt: Dayjs | null;
|
|
12
|
+
}
|
|
13
|
+
export declare class Int {
|
|
14
|
+
__Scalar__: "int";
|
|
15
|
+
}
|
|
16
|
+
export declare class Upload {
|
|
17
|
+
__Scalar__: "upload";
|
|
18
|
+
filename: string;
|
|
19
|
+
mimetype: string;
|
|
20
|
+
encoding: string;
|
|
21
|
+
createReadStream: () => ReadStream | Readable;
|
|
22
|
+
}
|
|
23
|
+
export declare class Float {
|
|
24
|
+
__Scalar__: "float";
|
|
25
|
+
}
|
|
26
|
+
export declare class ID {
|
|
27
|
+
__Scalar__: "id";
|
|
28
|
+
}
|
|
29
|
+
export declare class JSON {
|
|
30
|
+
__Scalar__: "json";
|
|
31
|
+
}
|
|
32
|
+
export type SingleFieldType = Int | Float | StringConstructor | BooleanConstructor | ID | DateConstructor | JSON | Type | GraphQLJSON | GraphQLUpload;
|
|
33
|
+
export declare const getNonArrayModel: <T = Type>(arraiedModel: T | T[]) => [T, number];
|
|
34
|
+
export declare const arraiedModel: <T = any>(modelRef: T, arrDepth?: number) => T | T[];
|
|
35
|
+
export declare const applyFnToArrayObjects: (arraiedData: any, fn: (arg: any) => any) => any[];
|
|
36
|
+
export declare const gqlScalars: readonly [StringConstructor, BooleanConstructor, DateConstructor, typeof ID, typeof Int, typeof Float, typeof Upload, typeof JSON, MapConstructor];
|
|
37
|
+
export type GqlScalar = (typeof gqlScalars)[number];
|
|
38
|
+
export declare const gqlScalarNames: readonly ["ID", "Int", "Float", "String", "Boolean", "Date", "Upload", "JSON", "Map"];
|
|
39
|
+
export type GqlScalarName = (typeof gqlScalarNames)[number];
|
|
40
|
+
export declare const scalarSet: Set<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor>;
|
|
41
|
+
export declare const scalarNameMap: Map<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor, "ID" | "Int" | "Float" | "String" | "Boolean" | "Date" | "Upload" | "JSON" | "Map">;
|
|
42
|
+
export declare const scalarArgMap: Map<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor, any>;
|
|
43
|
+
export declare const scalarDefaultMap: Map<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor, any>;
|
|
44
|
+
export declare const isGqlClass: (modelRef: Type) => boolean;
|
|
45
|
+
export declare const isGqlScalar: (modelRef: Type) => boolean;
|
|
46
|
+
export declare const isGqlMap: (modelRef: any) => boolean;
|
package/src/scalar.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import dayjsLib, { Dayjs } from "dayjs";
|
|
2
|
+
const dayjs = dayjsLib;
|
|
3
|
+
class BaseObject {
|
|
4
|
+
id;
|
|
5
|
+
createdAt;
|
|
6
|
+
updatedAt;
|
|
7
|
+
removedAt;
|
|
8
|
+
}
|
|
9
|
+
class Int {
|
|
10
|
+
__Scalar__;
|
|
11
|
+
}
|
|
12
|
+
class Upload {
|
|
13
|
+
__Scalar__;
|
|
14
|
+
filename;
|
|
15
|
+
mimetype;
|
|
16
|
+
encoding;
|
|
17
|
+
createReadStream;
|
|
18
|
+
}
|
|
19
|
+
class Float {
|
|
20
|
+
__Scalar__;
|
|
21
|
+
}
|
|
22
|
+
class ID {
|
|
23
|
+
__Scalar__;
|
|
24
|
+
}
|
|
25
|
+
class JSON {
|
|
26
|
+
__Scalar__;
|
|
27
|
+
}
|
|
28
|
+
const getNonArrayModel = (arraiedModel2) => {
|
|
29
|
+
let arrDepth = 0;
|
|
30
|
+
let target = arraiedModel2;
|
|
31
|
+
while (Array.isArray(target)) {
|
|
32
|
+
target = target[0];
|
|
33
|
+
arrDepth++;
|
|
34
|
+
}
|
|
35
|
+
return [target, arrDepth];
|
|
36
|
+
};
|
|
37
|
+
const arraiedModel = (modelRef, arrDepth = 0) => {
|
|
38
|
+
let target = modelRef;
|
|
39
|
+
for (let i = 0; i < arrDepth; i++)
|
|
40
|
+
target = [target];
|
|
41
|
+
return target;
|
|
42
|
+
};
|
|
43
|
+
const applyFnToArrayObjects = (arraiedData, fn) => {
|
|
44
|
+
if (Array.isArray(arraiedData))
|
|
45
|
+
return arraiedData.map((data) => applyFnToArrayObjects(data, fn));
|
|
46
|
+
return fn(arraiedData);
|
|
47
|
+
};
|
|
48
|
+
const gqlScalars = [String, Boolean, Date, ID, Int, Float, Upload, JSON, Map];
|
|
49
|
+
const gqlScalarNames = ["ID", "Int", "Float", "String", "Boolean", "Date", "Upload", "JSON", "Map"];
|
|
50
|
+
const scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON, Map]);
|
|
51
|
+
const scalarNameMap = /* @__PURE__ */ new Map([
|
|
52
|
+
[ID, "ID"],
|
|
53
|
+
[Int, "Int"],
|
|
54
|
+
[Float, "Float"],
|
|
55
|
+
[String, "String"],
|
|
56
|
+
[Boolean, "Boolean"],
|
|
57
|
+
[Date, "Date"],
|
|
58
|
+
[Upload, "Upload"],
|
|
59
|
+
[JSON, "JSON"],
|
|
60
|
+
[Map, "Map"]
|
|
61
|
+
]);
|
|
62
|
+
const scalarArgMap = /* @__PURE__ */ new Map([
|
|
63
|
+
[ID, null],
|
|
64
|
+
[String, ""],
|
|
65
|
+
[Boolean, false],
|
|
66
|
+
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
67
|
+
[Int, 0],
|
|
68
|
+
[Float, 0],
|
|
69
|
+
[JSON, {}],
|
|
70
|
+
[Map, {}]
|
|
71
|
+
]);
|
|
72
|
+
const scalarDefaultMap = /* @__PURE__ */ new Map([
|
|
73
|
+
[ID, null],
|
|
74
|
+
[String, ""],
|
|
75
|
+
[Boolean, false],
|
|
76
|
+
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
77
|
+
[Int, 0],
|
|
78
|
+
[Float, 0],
|
|
79
|
+
[JSON, {}]
|
|
80
|
+
]);
|
|
81
|
+
const isGqlClass = (modelRef) => !scalarSet.has(modelRef);
|
|
82
|
+
const isGqlScalar = (modelRef) => scalarSet.has(modelRef);
|
|
83
|
+
const isGqlMap = (modelRef) => modelRef === Map;
|
|
84
|
+
export {
|
|
85
|
+
BaseObject,
|
|
86
|
+
Dayjs,
|
|
87
|
+
Float,
|
|
88
|
+
ID,
|
|
89
|
+
Int,
|
|
90
|
+
JSON,
|
|
91
|
+
Upload,
|
|
92
|
+
applyFnToArrayObjects,
|
|
93
|
+
arraiedModel,
|
|
94
|
+
dayjs,
|
|
95
|
+
getNonArrayModel,
|
|
96
|
+
gqlScalarNames,
|
|
97
|
+
gqlScalars,
|
|
98
|
+
isGqlClass,
|
|
99
|
+
isGqlMap,
|
|
100
|
+
isGqlScalar,
|
|
101
|
+
scalarArgMap,
|
|
102
|
+
scalarDefaultMap,
|
|
103
|
+
scalarNameMap,
|
|
104
|
+
scalarSet
|
|
105
|
+
};
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type { SshOptions } from "tunnel-ssh";
|
|
2
|
+
export type Type<T = any> = new (...args: any[]) => T;
|
|
3
|
+
export type BufferLike = string | Buffer | DataView | number | ArrayBufferView | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly any[] | readonly number[];
|
|
4
|
+
export type GetObject<T> = Omit<{
|
|
5
|
+
[K in keyof T]: T[K];
|
|
6
|
+
}, "prototype">;
|
|
7
|
+
export type OptionOf<Obj> = {
|
|
8
|
+
[K in keyof Obj]?: Obj[K] | null;
|
|
9
|
+
};
|
|
10
|
+
export type UnType<T> = T extends new (...args: any) => infer U ? U : never;
|
|
11
|
+
export interface GraphQLUpload {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
specifiedByUrl: string;
|
|
15
|
+
serialize: any;
|
|
16
|
+
parseValue: any;
|
|
17
|
+
parseLiteral: any;
|
|
18
|
+
extensions: any;
|
|
19
|
+
astNode: any;
|
|
20
|
+
extensionASTNodes: any;
|
|
21
|
+
toConfig(): any;
|
|
22
|
+
toString(): string;
|
|
23
|
+
toJSON(): string;
|
|
24
|
+
inspect(): string;
|
|
25
|
+
}
|
|
26
|
+
export interface GraphQLJSON<TInternal = unknown, TExternal = TInternal> {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
specifiedByURL: string;
|
|
30
|
+
serialize: any;
|
|
31
|
+
parseValue: any;
|
|
32
|
+
parseLiteral: any;
|
|
33
|
+
extensions: any;
|
|
34
|
+
astNode: any;
|
|
35
|
+
extensionASTNodes: any;
|
|
36
|
+
get [Symbol.toStringTag](): string;
|
|
37
|
+
toConfig(): any;
|
|
38
|
+
toString(): string;
|
|
39
|
+
toJSON(): string;
|
|
40
|
+
}
|
package/src/types.js
ADDED
|
File without changes
|
package/project.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@akanjs/base",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "pkgs/@akanjs/base",
|
|
5
|
-
"projectType": "application",
|
|
6
|
-
"tags": [],
|
|
7
|
-
"targets": {
|
|
8
|
-
"build": {
|
|
9
|
-
"executor": "@nx/esbuild:esbuild",
|
|
10
|
-
"outputs": ["{options.outputPath}"],
|
|
11
|
-
"options": {
|
|
12
|
-
"outputPath": "dist/{projectRoot}",
|
|
13
|
-
"main": "{projectRoot}/index.ts",
|
|
14
|
-
"tsConfig": "{projectRoot}/tsconfig.json",
|
|
15
|
-
"format": ["esm"],
|
|
16
|
-
"declaration": true,
|
|
17
|
-
"bundle": false,
|
|
18
|
-
"generatePackageJson": true
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"lint": { "executor": "@nx/eslint:lint" }
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/base.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
export class Enum<T> {
|
|
2
|
-
readonly value: T; // for type
|
|
3
|
-
readonly valueMap: Map<T, number>;
|
|
4
|
-
constructor(readonly values: T[]) {
|
|
5
|
-
this.valueMap = new Map(values.map((value, idx) => [value, idx] as [T, number]));
|
|
6
|
-
}
|
|
7
|
-
has(value: T): boolean {
|
|
8
|
-
return this.valueMap.has(value);
|
|
9
|
-
}
|
|
10
|
-
indexOf(value: T): number {
|
|
11
|
-
const idx = this.valueMap.get(value);
|
|
12
|
-
if (idx === undefined) throw new Error(`Value ${value} is not in enum`);
|
|
13
|
-
return idx;
|
|
14
|
-
}
|
|
15
|
-
find(callback: (value: T, index: number, array: T[]) => boolean): T {
|
|
16
|
-
const val = this.values.find(callback);
|
|
17
|
-
if (val === undefined) throw new Error(`Value not found in enum`);
|
|
18
|
-
return val;
|
|
19
|
-
}
|
|
20
|
-
findIndex(callback: (value: T, index: number, array: T[]) => boolean): number {
|
|
21
|
-
const idx = this.values.findIndex(callback);
|
|
22
|
-
if (idx === -1) throw new Error(`Value not found in enum`);
|
|
23
|
-
return idx;
|
|
24
|
-
}
|
|
25
|
-
filter(callback: (value: T, index: number, array: T[]) => boolean): T[] {
|
|
26
|
-
return this.values.filter(callback);
|
|
27
|
-
}
|
|
28
|
-
map<R>(callback: (value: T, index: number, array: T[]) => R): R[] {
|
|
29
|
-
return this.values.map(callback);
|
|
30
|
-
}
|
|
31
|
-
forEach(callback: (value: T, index: number, array: T[]) => void): void {
|
|
32
|
-
this.values.forEach(callback);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export const enumOf = <T>(values: T[]) => new Enum(values);
|
|
36
|
-
export type EnumType<E> = E extends Enum<infer T> ? T : never;
|
|
37
|
-
|
|
38
|
-
export class DataList<Light extends { id: string }> {
|
|
39
|
-
// [immerable] = true;
|
|
40
|
-
#idMap: Map<string, number>;
|
|
41
|
-
length: number;
|
|
42
|
-
values: Light[];
|
|
43
|
-
constructor(data: Light[] | DataList<Light> = []) {
|
|
44
|
-
this.values = Array.isArray(data) ? [...data] : [...data.values];
|
|
45
|
-
this.#idMap = new Map(this.values.map((value, idx) => [value.id, idx]));
|
|
46
|
-
this.length = this.values.length;
|
|
47
|
-
}
|
|
48
|
-
indexOf(id: string) {
|
|
49
|
-
const idx = this.#idMap.get(id);
|
|
50
|
-
if (idx === undefined) throw new Error(`Value ${id} is not in list`);
|
|
51
|
-
return idx;
|
|
52
|
-
}
|
|
53
|
-
set(value: Light) {
|
|
54
|
-
const idx = this.#idMap.get(value.id);
|
|
55
|
-
if (idx !== undefined) this.values = [...this.values.slice(0, idx), value, ...this.values.slice(idx + 1)];
|
|
56
|
-
else {
|
|
57
|
-
this.#idMap.set(value.id, this.length);
|
|
58
|
-
this.values = [...this.values, value];
|
|
59
|
-
this.length++;
|
|
60
|
-
}
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
delete(id: string) {
|
|
64
|
-
const idx = this.#idMap.get(id);
|
|
65
|
-
if (idx === undefined) return this;
|
|
66
|
-
this.#idMap.delete(id);
|
|
67
|
-
this.values.splice(idx, 1);
|
|
68
|
-
this.values.slice(idx).forEach((value, i) => this.#idMap.set(value.id, i + idx));
|
|
69
|
-
this.length--;
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
get(id: string) {
|
|
73
|
-
const idx = this.#idMap.get(id);
|
|
74
|
-
if (idx === undefined) return undefined;
|
|
75
|
-
return this.values[idx];
|
|
76
|
-
}
|
|
77
|
-
at(idx: number) {
|
|
78
|
-
return this.values.at(idx);
|
|
79
|
-
}
|
|
80
|
-
pickAt(idx: number) {
|
|
81
|
-
const value = this.values.at(idx);
|
|
82
|
-
if (value === undefined) throw new Error(`Value at ${idx} is undefined`);
|
|
83
|
-
return value;
|
|
84
|
-
}
|
|
85
|
-
pick(id: string) {
|
|
86
|
-
return this.values[this.indexOf(id)];
|
|
87
|
-
}
|
|
88
|
-
has(id: string) {
|
|
89
|
-
return this.#idMap.has(id);
|
|
90
|
-
}
|
|
91
|
-
find(fn: (value: Light, idx: number) => boolean) {
|
|
92
|
-
const val = this.values.find(fn);
|
|
93
|
-
return val;
|
|
94
|
-
}
|
|
95
|
-
findIndex(fn: (value: Light, idx: number) => boolean) {
|
|
96
|
-
const val = this.values.findIndex(fn);
|
|
97
|
-
return val;
|
|
98
|
-
}
|
|
99
|
-
some(fn: (value: Light, idx: number) => boolean) {
|
|
100
|
-
return this.values.some(fn);
|
|
101
|
-
}
|
|
102
|
-
every(fn: (value: Light, idx: number) => boolean) {
|
|
103
|
-
return this.values.every(fn);
|
|
104
|
-
}
|
|
105
|
-
forEach(fn: (value: Light, idx: number) => void) {
|
|
106
|
-
this.values.forEach(fn);
|
|
107
|
-
}
|
|
108
|
-
map<T>(fn: (value: Light, idx: number) => T) {
|
|
109
|
-
return this.values.map(fn);
|
|
110
|
-
}
|
|
111
|
-
flatMap<T>(fn: (value: Light, idx: number, array: Light[]) => T | readonly T[]) {
|
|
112
|
-
return this.values.flatMap(fn);
|
|
113
|
-
}
|
|
114
|
-
sort(fn: (a: Light, b: Light) => number) {
|
|
115
|
-
return new DataList(this.values.sort(fn));
|
|
116
|
-
}
|
|
117
|
-
filter(fn: (value: Light, idx: number) => boolean) {
|
|
118
|
-
return new DataList(this.values.filter(fn));
|
|
119
|
-
}
|
|
120
|
-
reduce<T>(fn: (acc: T, value: Light, idx: number) => T, initialValue: T) {
|
|
121
|
-
return this.values.reduce(fn, initialValue);
|
|
122
|
-
}
|
|
123
|
-
slice(start: number, end = this.length) {
|
|
124
|
-
return new DataList(this.values.slice(start, end));
|
|
125
|
-
}
|
|
126
|
-
save() {
|
|
127
|
-
return new DataList(this);
|
|
128
|
-
}
|
|
129
|
-
[Symbol.iterator]() {
|
|
130
|
-
return this.values[Symbol.iterator]();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export const version = "0.9.0";
|
|
135
|
-
export const logo = `
|
|
136
|
-
_ _ _
|
|
137
|
-
/ \\ | | ____ _ _ __ (_)___
|
|
138
|
-
/ _ \\ | |/ / _' | '_ \\ | / __|
|
|
139
|
-
/ ___ \\| < (_| | | | |_ | \\__ \\
|
|
140
|
-
/_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
|
|
141
|
-
|__/ ver ${version}
|
|
142
|
-
? See more details on docs https://www.akanjs.com/docs
|
|
143
|
-
★ Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
|
|
144
|
-
|
|
145
|
-
`;
|
package/src/baseEnv.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
export type Environment = "testing" | "debug" | "develop" | "main";
|
|
2
|
-
export interface BaseEnv {
|
|
3
|
-
appName: string;
|
|
4
|
-
environment: Environment;
|
|
5
|
-
operationType: "server" | "client";
|
|
6
|
-
operationMode: "local" | "edge" | "cloud" | "module";
|
|
7
|
-
networkType: "mainnet" | "testnet" | "debugnet";
|
|
8
|
-
}
|
|
9
|
-
export type BackendEnv = BaseEnv & {
|
|
10
|
-
hostname: string | null;
|
|
11
|
-
appCode: number;
|
|
12
|
-
mongo: { password?: string };
|
|
13
|
-
port?: number;
|
|
14
|
-
mongoUri?: string;
|
|
15
|
-
redisUri?: string;
|
|
16
|
-
meiliUri?: string;
|
|
17
|
-
onCleanup?: () => Promise<void>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
//! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
|
|
21
|
-
// https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#runtime-environment-variables
|
|
22
|
-
const appName = process.env.NEXT_PUBLIC_APP_NAME ?? process.env.NX_TASK_TARGET_PROJECT ?? "unknown";
|
|
23
|
-
if (appName === "unknown")
|
|
24
|
-
throw new Error("environment variable NEXT_PUBLIC_APP_NAME or NX_TASK_TARGET_PROJECT is required");
|
|
25
|
-
const environment = (process.env.NEXT_PUBLIC_ENV ?? "debug") as BaseEnv["environment"];
|
|
26
|
-
const operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
|
|
27
|
-
const operationMode = (process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud") as BaseEnv["operationMode"];
|
|
28
|
-
const networkType = (process.env.NEXT_PUBLIC_NETWORK_TYPE ??
|
|
29
|
-
(environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet")) as BaseEnv["networkType"];
|
|
30
|
-
|
|
31
|
-
export const baseEnv: BaseEnv = {
|
|
32
|
-
appName,
|
|
33
|
-
environment,
|
|
34
|
-
operationType,
|
|
35
|
-
operationMode,
|
|
36
|
-
networkType,
|
|
37
|
-
} as const;
|
|
38
|
-
|
|
39
|
-
export type BaseClientEnv = BaseEnv & {
|
|
40
|
-
side: "server" | "client";
|
|
41
|
-
renderMode: "ssr" | "csr";
|
|
42
|
-
websocket: boolean;
|
|
43
|
-
clientHost: string;
|
|
44
|
-
clientPort: number;
|
|
45
|
-
clientHttpProtocol: "http:" | "https:";
|
|
46
|
-
clientHttpUri: string;
|
|
47
|
-
serverHost: string;
|
|
48
|
-
serverPort: number;
|
|
49
|
-
serverHttpProtocol: "http:" | "https:";
|
|
50
|
-
serverHttpUri: string;
|
|
51
|
-
serverGraphqlUri: string;
|
|
52
|
-
serverWsProtocol: "ws:" | "wss:";
|
|
53
|
-
serverWsUri: string;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const side = typeof window === "undefined" ? "server" : "client";
|
|
57
|
-
const renderMode = (process.env.RENDER_ENV ?? "ssr") as BaseClientEnv["renderMode"];
|
|
58
|
-
const clientHost =
|
|
59
|
-
process.env.NEXT_PUBLIC_CLIENT_HOST ??
|
|
60
|
-
(operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
|
|
61
|
-
const clientPort = parseInt(
|
|
62
|
-
process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? (renderMode === "ssr" ? "4200" : "4201") : "443")
|
|
63
|
-
);
|
|
64
|
-
const clientHttpProtocol =
|
|
65
|
-
side === "client"
|
|
66
|
-
? (window.location.protocol as "http:" | "https:")
|
|
67
|
-
: clientHost === "localhost"
|
|
68
|
-
? "http:"
|
|
69
|
-
: "https:";
|
|
70
|
-
const clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
|
|
71
|
-
const serverHost =
|
|
72
|
-
process.env.SERVER_HOST ??
|
|
73
|
-
(operationMode === "local"
|
|
74
|
-
? typeof window === "undefined"
|
|
75
|
-
? "localhost"
|
|
76
|
-
: window.location.host.split(":")[0]
|
|
77
|
-
: renderMode === "csr"
|
|
78
|
-
? `${appName}-${environment}.akamir.com`
|
|
79
|
-
: side === "client"
|
|
80
|
-
? window.location.host.split(":")[0]
|
|
81
|
-
: operationMode === "cloud"
|
|
82
|
-
? `backend-svc.${appName}-${environment}.svc.cluster.local`
|
|
83
|
-
: "localhost");
|
|
84
|
-
|
|
85
|
-
const serverPort = parseInt(
|
|
86
|
-
process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
|
|
87
|
-
);
|
|
88
|
-
const serverHttpProtocol = side === "client" ? (window.location.protocol as "http:" | "https:") : "http:";
|
|
89
|
-
const serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
|
|
90
|
-
const serverGraphqlUri = `${serverHttpUri}/graphql`;
|
|
91
|
-
const serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
|
|
92
|
-
const serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
|
|
93
|
-
|
|
94
|
-
export const baseClientEnv: BaseClientEnv = {
|
|
95
|
-
...baseEnv,
|
|
96
|
-
side,
|
|
97
|
-
renderMode,
|
|
98
|
-
websocket: true,
|
|
99
|
-
clientHost,
|
|
100
|
-
clientPort,
|
|
101
|
-
clientHttpProtocol,
|
|
102
|
-
clientHttpUri,
|
|
103
|
-
serverHost,
|
|
104
|
-
serverPort,
|
|
105
|
-
serverHttpProtocol,
|
|
106
|
-
serverHttpUri,
|
|
107
|
-
serverGraphqlUri,
|
|
108
|
-
serverWsProtocol,
|
|
109
|
-
serverWsUri,
|
|
110
|
-
} as const;
|
package/src/scalar.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import dayjsLib, { Dayjs } from "dayjs";
|
|
2
|
-
import type { ReadStream } from "fs";
|
|
3
|
-
import type { Readable } from "stream";
|
|
4
|
-
|
|
5
|
-
import type { GraphQLJSON, GraphQLUpload, Type } from "./types";
|
|
6
|
-
|
|
7
|
-
export { Dayjs };
|
|
8
|
-
|
|
9
|
-
export const dayjs = dayjsLib;
|
|
10
|
-
export class BaseObject {
|
|
11
|
-
id: string;
|
|
12
|
-
createdAt: Dayjs;
|
|
13
|
-
updatedAt: Dayjs;
|
|
14
|
-
removedAt: Dayjs | null;
|
|
15
|
-
}
|
|
16
|
-
export class Int {
|
|
17
|
-
__Scalar__: "int";
|
|
18
|
-
}
|
|
19
|
-
export class Upload {
|
|
20
|
-
__Scalar__: "upload";
|
|
21
|
-
filename: string;
|
|
22
|
-
mimetype: string;
|
|
23
|
-
encoding: string;
|
|
24
|
-
createReadStream: () => ReadStream | Readable;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class Float {
|
|
28
|
-
__Scalar__: "float";
|
|
29
|
-
}
|
|
30
|
-
export class ID {
|
|
31
|
-
__Scalar__: "id";
|
|
32
|
-
}
|
|
33
|
-
export class JSON {
|
|
34
|
-
__Scalar__: "json";
|
|
35
|
-
}
|
|
36
|
-
export type SingleFieldType =
|
|
37
|
-
| Int
|
|
38
|
-
| Float
|
|
39
|
-
| StringConstructor
|
|
40
|
-
| BooleanConstructor
|
|
41
|
-
| ID
|
|
42
|
-
| DateConstructor
|
|
43
|
-
| JSON
|
|
44
|
-
| Type
|
|
45
|
-
| GraphQLJSON
|
|
46
|
-
| GraphQLUpload;
|
|
47
|
-
|
|
48
|
-
export const getNonArrayModel = <T = Type>(arraiedModel: T | T[]): [T, number] => {
|
|
49
|
-
let arrDepth = 0;
|
|
50
|
-
let target: T | T[] = arraiedModel;
|
|
51
|
-
while (Array.isArray(target)) {
|
|
52
|
-
target = target[0];
|
|
53
|
-
arrDepth++;
|
|
54
|
-
}
|
|
55
|
-
return [target, arrDepth];
|
|
56
|
-
};
|
|
57
|
-
export const arraiedModel = <T = any>(modelRef: T, arrDepth = 0) => {
|
|
58
|
-
let target: T | T[] | T[][] | T[][][] = modelRef;
|
|
59
|
-
for (let i = 0; i < arrDepth; i++) target = [target as T];
|
|
60
|
-
return target;
|
|
61
|
-
};
|
|
62
|
-
export const applyFnToArrayObjects = (arraiedData: any, fn: (arg: any) => any): any[] => {
|
|
63
|
-
if (Array.isArray(arraiedData)) return arraiedData.map((data) => applyFnToArrayObjects(data, fn) as unknown);
|
|
64
|
-
return fn(arraiedData) as unknown as any[];
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export const gqlScalars = [String, Boolean, Date, ID, Int, Float, Upload, JSON, Map] as const;
|
|
68
|
-
export type GqlScalar = (typeof gqlScalars)[number];
|
|
69
|
-
export const gqlScalarNames = ["ID", "Int", "Float", "String", "Boolean", "Date", "Upload", "JSON", "Map"] as const;
|
|
70
|
-
export type GqlScalarName = (typeof gqlScalarNames)[number];
|
|
71
|
-
export const scalarSet = new Set<GqlScalar>([String, Boolean, Date, ID, Int, Float, Upload, JSON, Map]);
|
|
72
|
-
export const scalarNameMap = new Map<GqlScalar, GqlScalarName>([
|
|
73
|
-
[ID, "ID"],
|
|
74
|
-
[Int, "Int"],
|
|
75
|
-
[Float, "Float"],
|
|
76
|
-
[String, "String"],
|
|
77
|
-
[Boolean, "Boolean"],
|
|
78
|
-
[Date, "Date"],
|
|
79
|
-
[Upload, "Upload"],
|
|
80
|
-
[JSON, "JSON"],
|
|
81
|
-
[Map, "Map"],
|
|
82
|
-
]);
|
|
83
|
-
export const scalarArgMap = new Map<GqlScalar, any>([
|
|
84
|
-
[ID, null],
|
|
85
|
-
[String, ""],
|
|
86
|
-
[Boolean, false],
|
|
87
|
-
[Date, dayjs(new Date(-1))],
|
|
88
|
-
[Int, 0],
|
|
89
|
-
[Float, 0],
|
|
90
|
-
[JSON, {}],
|
|
91
|
-
[Map, {}],
|
|
92
|
-
]);
|
|
93
|
-
export const scalarDefaultMap = new Map<GqlScalar, any>([
|
|
94
|
-
[ID, null],
|
|
95
|
-
[String, ""],
|
|
96
|
-
[Boolean, false],
|
|
97
|
-
[Date, dayjs(new Date(-1))],
|
|
98
|
-
[Int, 0],
|
|
99
|
-
[Float, 0],
|
|
100
|
-
[JSON, {}],
|
|
101
|
-
]);
|
|
102
|
-
export const isGqlClass = (modelRef: Type) => !scalarSet.has(modelRef);
|
|
103
|
-
export const isGqlScalar = (modelRef: Type) => scalarSet.has(modelRef);
|
|
104
|
-
export const isGqlMap = (modelRef: any) => modelRef === Map;
|
package/src/types.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export type Type<T = any> = new (...args: any[]) => T;
|
|
2
|
-
|
|
3
|
-
export type BufferLike =
|
|
4
|
-
| string
|
|
5
|
-
| Buffer
|
|
6
|
-
| DataView
|
|
7
|
-
| number
|
|
8
|
-
| ArrayBufferView
|
|
9
|
-
| Uint8Array
|
|
10
|
-
| ArrayBuffer
|
|
11
|
-
| SharedArrayBuffer
|
|
12
|
-
| readonly any[]
|
|
13
|
-
| readonly number[];
|
|
14
|
-
|
|
15
|
-
export type GetObject<T> = Omit<{ [K in keyof T]: T[K] }, "prototype">;
|
|
16
|
-
export type OptionOf<Obj> = {
|
|
17
|
-
[K in keyof Obj]?: Obj[K] | null;
|
|
18
|
-
};
|
|
19
|
-
export type UnType<T> = T extends new (...args: any) => infer U ? U : never;
|
|
20
|
-
|
|
21
|
-
export interface GraphQLUpload {
|
|
22
|
-
name: string;
|
|
23
|
-
description: string;
|
|
24
|
-
specifiedByUrl: string;
|
|
25
|
-
serialize: any;
|
|
26
|
-
parseValue: any;
|
|
27
|
-
parseLiteral: any;
|
|
28
|
-
extensions: any;
|
|
29
|
-
astNode: any;
|
|
30
|
-
extensionASTNodes: any;
|
|
31
|
-
toConfig(): any;
|
|
32
|
-
toString(): string;
|
|
33
|
-
toJSON(): string;
|
|
34
|
-
inspect(): string;
|
|
35
|
-
}
|
|
36
|
-
export interface GraphQLJSON<TInternal = unknown, TExternal = TInternal> {
|
|
37
|
-
name: string;
|
|
38
|
-
description: string;
|
|
39
|
-
specifiedByURL: string;
|
|
40
|
-
serialize: any;
|
|
41
|
-
parseValue: any;
|
|
42
|
-
parseLiteral: any;
|
|
43
|
-
extensions: any;
|
|
44
|
-
astNode: any;
|
|
45
|
-
extensionASTNodes: any;
|
|
46
|
-
get [Symbol.toStringTag](): string;
|
|
47
|
-
toConfig(): any;
|
|
48
|
-
toString(): string;
|
|
49
|
-
toJSON(): string;
|
|
50
|
-
}
|
package/tsconfig.json
DELETED
package/tsconfig.spec.json
DELETED
/package/{index.ts → index.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|