@akanjs/signal 0.0.97 → 0.0.99
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.cjs +17 -0
- package/index.js +1 -17
- package/package.json +5 -5
- package/src/baseFetch.cjs +34 -0
- package/src/baseFetch.js +5 -24
- package/src/{client.mjs → client.cjs} +40 -21
- package/src/client.js +21 -40
- package/src/doc.cjs +101 -0
- package/src/doc.js +23 -42
- package/src/{gql.mjs → gql.cjs} +141 -144
- package/src/gql.js +144 -141
- package/src/immerify.cjs +35 -0
- package/src/immerify.js +7 -26
- package/src/index.cjs +30 -0
- package/src/index.js +9 -29
- package/src/{signalDecorators.mjs → signalDecorators.cjs} +95 -87
- package/src/signalDecorators.js +87 -95
- package/index.mjs +0 -1
- package/src/baseFetch.mjs +0 -15
- package/src/doc.mjs +0 -82
- package/src/immerify.mjs +0 -16
- package/src/index.mjs +0 -10
package/index.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var signal_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(signal_exports);
|
|
17
|
+
__reExport(signal_exports, require("./src"), module.exports);
|
package/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var signal_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(signal_exports);
|
|
17
|
-
__reExport(signal_exports, require("./src"), module.exports);
|
|
1
|
+
export * from "./src";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/signal",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "0.0.99",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"require": "./index.
|
|
27
|
-
"import": "./index.
|
|
26
|
+
"require": "./index.cjs",
|
|
27
|
+
"import": "./index.js"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"esbuild": {
|
|
31
|
-
"platform": "
|
|
31
|
+
"platform": "neutral"
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 baseFetch_exports = {};
|
|
19
|
+
__export(baseFetch_exports, {
|
|
20
|
+
baseFetch: () => baseFetch
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(baseFetch_exports);
|
|
23
|
+
var import_client = require("./client");
|
|
24
|
+
const nativeFetch = fetch;
|
|
25
|
+
const baseFetch = Object.assign(nativeFetch, {
|
|
26
|
+
client: import_client.client,
|
|
27
|
+
clone: function(option = {}) {
|
|
28
|
+
return {
|
|
29
|
+
...this,
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
31
|
+
client: this.client.clone(option)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
});
|
package/src/baseFetch.js
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
|
|
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 baseFetch_exports = {};
|
|
19
|
-
__export(baseFetch_exports, {
|
|
20
|
-
baseFetch: () => baseFetch
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(baseFetch_exports);
|
|
23
|
-
var import_client = require("./client");
|
|
1
|
+
import { client } from "./client";
|
|
24
2
|
const nativeFetch = fetch;
|
|
25
3
|
const baseFetch = Object.assign(nativeFetch, {
|
|
26
|
-
client
|
|
4
|
+
client,
|
|
27
5
|
clone: function(option = {}) {
|
|
28
6
|
return {
|
|
29
7
|
...this,
|
|
@@ -32,3 +10,6 @@ const baseFetch = Object.assign(nativeFetch, {
|
|
|
32
10
|
};
|
|
33
11
|
}
|
|
34
12
|
});
|
|
13
|
+
export {
|
|
14
|
+
baseFetch
|
|
15
|
+
};
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 client_exports = {};
|
|
19
|
+
__export(client_exports, {
|
|
20
|
+
client: () => client
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(client_exports);
|
|
23
|
+
var import_base = require("@akanjs/base");
|
|
24
|
+
var import_common = require("@akanjs/common");
|
|
25
|
+
var import_core = require("@urql/core");
|
|
26
|
+
var import_socket = require("socket.io-client");
|
|
5
27
|
class SocketIo {
|
|
6
28
|
socket;
|
|
7
29
|
roomSubscribeMap = /* @__PURE__ */ new Map();
|
|
8
30
|
constructor(uri) {
|
|
9
|
-
this.socket = io(uri, { transports: ["websocket"] });
|
|
31
|
+
this.socket = (0, import_socket.io)(uri, { transports: ["websocket"] });
|
|
10
32
|
this.socket.on("connect", () => {
|
|
11
33
|
this.roomSubscribeMap.forEach((option) => {
|
|
12
34
|
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
@@ -51,22 +73,22 @@ class SocketIo {
|
|
|
51
73
|
class Client {
|
|
52
74
|
static globalIoMap = /* @__PURE__ */ new Map();
|
|
53
75
|
static tokenStore = /* @__PURE__ */ new Map();
|
|
54
|
-
async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
|
|
55
|
-
if (baseClientEnv.side === "server")
|
|
76
|
+
async waitUntilWebSocketConnected(ws = import_base.baseClientEnv.serverWsUri) {
|
|
77
|
+
if (import_base.baseClientEnv.side === "server")
|
|
56
78
|
return true;
|
|
57
79
|
while (!this.getIo(ws).socket.connected) {
|
|
58
|
-
Logger.verbose("waiting for websocket to initialize...");
|
|
59
|
-
await sleep(300);
|
|
80
|
+
import_common.Logger.verbose("waiting for websocket to initialize...");
|
|
81
|
+
await (0, import_common.sleep)(300);
|
|
60
82
|
}
|
|
61
83
|
}
|
|
62
84
|
isInitialized = false;
|
|
63
|
-
uri = baseClientEnv.serverGraphqlUri;
|
|
64
|
-
ws = baseClientEnv.serverWsUri;
|
|
85
|
+
uri = import_base.baseClientEnv.serverGraphqlUri;
|
|
86
|
+
ws = import_base.baseClientEnv.serverWsUri;
|
|
65
87
|
udp = null;
|
|
66
|
-
gql = createClient({ url: this.uri, fetch, exchanges: [cacheExchange, fetchExchange] });
|
|
88
|
+
gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
|
|
67
89
|
jwt = null;
|
|
68
90
|
async getJwt() {
|
|
69
|
-
const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
|
|
91
|
+
const isNextServer = import_base.baseClientEnv.side === "server" && import_base.baseEnv.operationType === "client";
|
|
70
92
|
if (isNextServer) {
|
|
71
93
|
const nextHeaders = require("next/headers");
|
|
72
94
|
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
@@ -80,7 +102,7 @@ class Client {
|
|
|
80
102
|
this.setIo(data.ws);
|
|
81
103
|
this.isInitialized = true;
|
|
82
104
|
}
|
|
83
|
-
setIo(ws = baseClientEnv.serverWsUri) {
|
|
105
|
+
setIo(ws = import_base.baseClientEnv.serverWsUri) {
|
|
84
106
|
this.ws = ws;
|
|
85
107
|
const existingIo = Client.globalIoMap.get(ws);
|
|
86
108
|
if (existingIo) {
|
|
@@ -90,7 +112,7 @@ class Client {
|
|
|
90
112
|
this.io = new SocketIo(ws);
|
|
91
113
|
Client.globalIoMap.set(ws, this.io);
|
|
92
114
|
}
|
|
93
|
-
getIo(ws = baseClientEnv.serverWsUri) {
|
|
115
|
+
getIo(ws = import_base.baseClientEnv.serverWsUri) {
|
|
94
116
|
const existingIo = Client.globalIoMap.get(ws);
|
|
95
117
|
if (existingIo)
|
|
96
118
|
return existingIo;
|
|
@@ -98,12 +120,12 @@ class Client {
|
|
|
98
120
|
Client.globalIoMap.set(ws, io2);
|
|
99
121
|
return io2;
|
|
100
122
|
}
|
|
101
|
-
setLink(uri = baseClientEnv.serverGraphqlUri) {
|
|
123
|
+
setLink(uri = import_base.baseClientEnv.serverGraphqlUri) {
|
|
102
124
|
this.uri = uri;
|
|
103
|
-
this.gql = createClient({
|
|
125
|
+
this.gql = (0, import_core.createClient)({
|
|
104
126
|
url: this.uri,
|
|
105
127
|
fetch,
|
|
106
|
-
exchanges: [cacheExchange, fetchExchange],
|
|
128
|
+
exchanges: [import_core.cacheExchange, import_core.fetchExchange],
|
|
107
129
|
// requestPolicy: "network-only",
|
|
108
130
|
fetchOptions: () => {
|
|
109
131
|
return {
|
|
@@ -140,6 +162,3 @@ class Client {
|
|
|
140
162
|
}
|
|
141
163
|
}
|
|
142
164
|
const client = new Client();
|
|
143
|
-
export {
|
|
144
|
-
client
|
|
145
|
-
};
|
package/src/client.js
CHANGED
|
@@ -1,34 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 client_exports = {};
|
|
19
|
-
__export(client_exports, {
|
|
20
|
-
client: () => client
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(client_exports);
|
|
23
|
-
var import_base = require("@akanjs/base");
|
|
24
|
-
var import_common = require("@akanjs/common");
|
|
25
|
-
var import_core = require("@urql/core");
|
|
26
|
-
var import_socket = require("socket.io-client");
|
|
1
|
+
import { baseClientEnv, baseEnv } from "@akanjs/base";
|
|
2
|
+
import { Logger, sleep } from "@akanjs/common";
|
|
3
|
+
import { cacheExchange, createClient, fetchExchange } from "@urql/core";
|
|
4
|
+
import { io } from "socket.io-client";
|
|
27
5
|
class SocketIo {
|
|
28
6
|
socket;
|
|
29
7
|
roomSubscribeMap = /* @__PURE__ */ new Map();
|
|
30
8
|
constructor(uri) {
|
|
31
|
-
this.socket =
|
|
9
|
+
this.socket = io(uri, { transports: ["websocket"] });
|
|
32
10
|
this.socket.on("connect", () => {
|
|
33
11
|
this.roomSubscribeMap.forEach((option) => {
|
|
34
12
|
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
@@ -73,22 +51,22 @@ class SocketIo {
|
|
|
73
51
|
class Client {
|
|
74
52
|
static globalIoMap = /* @__PURE__ */ new Map();
|
|
75
53
|
static tokenStore = /* @__PURE__ */ new Map();
|
|
76
|
-
async waitUntilWebSocketConnected(ws =
|
|
77
|
-
if (
|
|
54
|
+
async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
|
|
55
|
+
if (baseClientEnv.side === "server")
|
|
78
56
|
return true;
|
|
79
57
|
while (!this.getIo(ws).socket.connected) {
|
|
80
|
-
|
|
81
|
-
await
|
|
58
|
+
Logger.verbose("waiting for websocket to initialize...");
|
|
59
|
+
await sleep(300);
|
|
82
60
|
}
|
|
83
61
|
}
|
|
84
62
|
isInitialized = false;
|
|
85
|
-
uri =
|
|
86
|
-
ws =
|
|
63
|
+
uri = baseClientEnv.serverGraphqlUri;
|
|
64
|
+
ws = baseClientEnv.serverWsUri;
|
|
87
65
|
udp = null;
|
|
88
|
-
gql =
|
|
66
|
+
gql = createClient({ url: this.uri, fetch, exchanges: [cacheExchange, fetchExchange] });
|
|
89
67
|
jwt = null;
|
|
90
68
|
async getJwt() {
|
|
91
|
-
const isNextServer =
|
|
69
|
+
const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
|
|
92
70
|
if (isNextServer) {
|
|
93
71
|
const nextHeaders = require("next/headers");
|
|
94
72
|
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
@@ -102,7 +80,7 @@ class Client {
|
|
|
102
80
|
this.setIo(data.ws);
|
|
103
81
|
this.isInitialized = true;
|
|
104
82
|
}
|
|
105
|
-
setIo(ws =
|
|
83
|
+
setIo(ws = baseClientEnv.serverWsUri) {
|
|
106
84
|
this.ws = ws;
|
|
107
85
|
const existingIo = Client.globalIoMap.get(ws);
|
|
108
86
|
if (existingIo) {
|
|
@@ -112,7 +90,7 @@ class Client {
|
|
|
112
90
|
this.io = new SocketIo(ws);
|
|
113
91
|
Client.globalIoMap.set(ws, this.io);
|
|
114
92
|
}
|
|
115
|
-
getIo(ws =
|
|
93
|
+
getIo(ws = baseClientEnv.serverWsUri) {
|
|
116
94
|
const existingIo = Client.globalIoMap.get(ws);
|
|
117
95
|
if (existingIo)
|
|
118
96
|
return existingIo;
|
|
@@ -120,12 +98,12 @@ class Client {
|
|
|
120
98
|
Client.globalIoMap.set(ws, io2);
|
|
121
99
|
return io2;
|
|
122
100
|
}
|
|
123
|
-
setLink(uri =
|
|
101
|
+
setLink(uri = baseClientEnv.serverGraphqlUri) {
|
|
124
102
|
this.uri = uri;
|
|
125
|
-
this.gql =
|
|
103
|
+
this.gql = createClient({
|
|
126
104
|
url: this.uri,
|
|
127
105
|
fetch,
|
|
128
|
-
exchanges: [
|
|
106
|
+
exchanges: [cacheExchange, fetchExchange],
|
|
129
107
|
// requestPolicy: "network-only",
|
|
130
108
|
fetchOptions: () => {
|
|
131
109
|
return {
|
|
@@ -162,3 +140,6 @@ class Client {
|
|
|
162
140
|
}
|
|
163
141
|
}
|
|
164
142
|
const client = new Client();
|
|
143
|
+
export {
|
|
144
|
+
client
|
|
145
|
+
};
|
package/src/doc.cjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
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 doc_exports = {};
|
|
19
|
+
__export(doc_exports, {
|
|
20
|
+
getExampleData: () => getExampleData,
|
|
21
|
+
makeRequestExample: () => makeRequestExample,
|
|
22
|
+
makeResponseExample: () => makeResponseExample
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(doc_exports);
|
|
25
|
+
var import_base = require("@akanjs/base");
|
|
26
|
+
var import_constant = require("@akanjs/constant");
|
|
27
|
+
var import_signalDecorators = require("./signalDecorators");
|
|
28
|
+
class ResponseExampleStorage {
|
|
29
|
+
}
|
|
30
|
+
const getPredefinedRequestExample = (modelRef) => {
|
|
31
|
+
return Reflect.getMetadata(modelRef, ResponseExampleStorage.prototype);
|
|
32
|
+
};
|
|
33
|
+
const getPredefinedResponseExample = (modelRef) => {
|
|
34
|
+
return Reflect.getMetadata(modelRef, ResponseExampleStorage.prototype);
|
|
35
|
+
};
|
|
36
|
+
const getResponseExample = (ref) => {
|
|
37
|
+
const [modelRef, arrDepth] = (0, import_base.getNonArrayModel)(ref);
|
|
38
|
+
const existing = getPredefinedRequestExample(modelRef);
|
|
39
|
+
if (existing)
|
|
40
|
+
return existing;
|
|
41
|
+
const isScalar = (0, import_base.isGqlScalar)(modelRef);
|
|
42
|
+
if (isScalar)
|
|
43
|
+
return (0, import_base.arraiedModel)((0, import_constant.getScalarExample)(modelRef), arrDepth);
|
|
44
|
+
const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
|
|
45
|
+
const example = {};
|
|
46
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
47
|
+
if (fieldMeta.example)
|
|
48
|
+
example[fieldMeta.key] = fieldMeta.example;
|
|
49
|
+
else if (fieldMeta.enum)
|
|
50
|
+
example[fieldMeta.key] = (0, import_base.arraiedModel)(fieldMeta.enum.values[0], fieldMeta.arrDepth);
|
|
51
|
+
else
|
|
52
|
+
example[fieldMeta.key] = getResponseExample(fieldMeta.modelRef);
|
|
53
|
+
});
|
|
54
|
+
const result = (0, import_base.arraiedModel)(example, arrDepth);
|
|
55
|
+
Reflect.defineMetadata(ref, result, ResponseExampleStorage.prototype);
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
class RequestExampleStorage {
|
|
59
|
+
}
|
|
60
|
+
const getRequestExample = (ref) => {
|
|
61
|
+
const existing = getPredefinedRequestExample(ref);
|
|
62
|
+
if (existing)
|
|
63
|
+
return existing;
|
|
64
|
+
const fieldMetas = (0, import_constant.getFieldMetas)(ref);
|
|
65
|
+
const example = {};
|
|
66
|
+
const isScalar = (0, import_base.isGqlScalar)(ref);
|
|
67
|
+
if (isScalar)
|
|
68
|
+
return (0, import_constant.getScalarExample)(ref);
|
|
69
|
+
else {
|
|
70
|
+
fieldMetas.forEach((fieldMeta) => {
|
|
71
|
+
if (!fieldMeta.isScalar && fieldMeta.isClass)
|
|
72
|
+
example[fieldMeta.key] = "ObjectID";
|
|
73
|
+
else
|
|
74
|
+
example[fieldMeta.key] = fieldMeta.example ?? fieldMeta.enum ? (0, import_base.arraiedModel)(fieldMeta.example ?? (fieldMeta.enum?.values)[0], fieldMeta.optArrDepth) : (0, import_base.arraiedModel)(getRequestExample(fieldMeta.modelRef), fieldMeta.arrDepth);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
Reflect.defineMetadata(ref, example, RequestExampleStorage.prototype);
|
|
78
|
+
return example;
|
|
79
|
+
};
|
|
80
|
+
const makeRequestExample = (sigRef, key) => {
|
|
81
|
+
const [argMetas] = (0, import_signalDecorators.getArgMetas)(sigRef, key);
|
|
82
|
+
return getExampleData(argMetas);
|
|
83
|
+
};
|
|
84
|
+
const getExampleData = (argMetas, signalType = "graphql") => Object.fromEntries(
|
|
85
|
+
argMetas.filter((argMeta) => argMeta.type !== "Upload").map((argMeta) => {
|
|
86
|
+
const [argRef, argArrDepth] = (0, import_base.getNonArrayModel)(argMeta.returns());
|
|
87
|
+
const example = argMeta.argsOption.example ?? getRequestExample(argRef);
|
|
88
|
+
return [
|
|
89
|
+
argMeta.name,
|
|
90
|
+
(0, import_base.arraiedModel)(
|
|
91
|
+
signalType === "restapi" && argRef.prototype === import_base.JSON.prototype ? JSON.stringify(example, null, 2) : example,
|
|
92
|
+
argArrDepth
|
|
93
|
+
)
|
|
94
|
+
];
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
const makeResponseExample = (sigRef, key) => {
|
|
98
|
+
const gqlMeta = (0, import_signalDecorators.getGqlMeta)(sigRef, key);
|
|
99
|
+
const example = getResponseExample(gqlMeta.returns());
|
|
100
|
+
return example;
|
|
101
|
+
};
|
package/src/doc.js
CHANGED
|
@@ -1,30 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 doc_exports = {};
|
|
19
|
-
__export(doc_exports, {
|
|
20
|
-
getExampleData: () => getExampleData,
|
|
21
|
-
makeRequestExample: () => makeRequestExample,
|
|
22
|
-
makeResponseExample: () => makeResponseExample
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(doc_exports);
|
|
25
|
-
var import_base = require("@akanjs/base");
|
|
26
|
-
var import_constant = require("@akanjs/constant");
|
|
27
|
-
var import_signalDecorators = require("./signalDecorators");
|
|
1
|
+
import { arraiedModel, getNonArrayModel, isGqlScalar, JSON as GqlJSON } from "@akanjs/base";
|
|
2
|
+
import { getFieldMetas, getScalarExample } from "@akanjs/constant";
|
|
3
|
+
import { getArgMetas, getGqlMeta } from "./signalDecorators";
|
|
28
4
|
class ResponseExampleStorage {
|
|
29
5
|
}
|
|
30
6
|
const getPredefinedRequestExample = (modelRef) => {
|
|
@@ -34,24 +10,24 @@ const getPredefinedResponseExample = (modelRef) => {
|
|
|
34
10
|
return Reflect.getMetadata(modelRef, ResponseExampleStorage.prototype);
|
|
35
11
|
};
|
|
36
12
|
const getResponseExample = (ref) => {
|
|
37
|
-
const [modelRef, arrDepth] =
|
|
13
|
+
const [modelRef, arrDepth] = getNonArrayModel(ref);
|
|
38
14
|
const existing = getPredefinedRequestExample(modelRef);
|
|
39
15
|
if (existing)
|
|
40
16
|
return existing;
|
|
41
|
-
const isScalar =
|
|
17
|
+
const isScalar = isGqlScalar(modelRef);
|
|
42
18
|
if (isScalar)
|
|
43
|
-
return
|
|
44
|
-
const fieldMetas =
|
|
19
|
+
return arraiedModel(getScalarExample(modelRef), arrDepth);
|
|
20
|
+
const fieldMetas = getFieldMetas(modelRef);
|
|
45
21
|
const example = {};
|
|
46
22
|
fieldMetas.forEach((fieldMeta) => {
|
|
47
23
|
if (fieldMeta.example)
|
|
48
24
|
example[fieldMeta.key] = fieldMeta.example;
|
|
49
25
|
else if (fieldMeta.enum)
|
|
50
|
-
example[fieldMeta.key] =
|
|
26
|
+
example[fieldMeta.key] = arraiedModel(fieldMeta.enum.values[0], fieldMeta.arrDepth);
|
|
51
27
|
else
|
|
52
28
|
example[fieldMeta.key] = getResponseExample(fieldMeta.modelRef);
|
|
53
29
|
});
|
|
54
|
-
const result =
|
|
30
|
+
const result = arraiedModel(example, arrDepth);
|
|
55
31
|
Reflect.defineMetadata(ref, result, ResponseExampleStorage.prototype);
|
|
56
32
|
return result;
|
|
57
33
|
};
|
|
@@ -61,41 +37,46 @@ const getRequestExample = (ref) => {
|
|
|
61
37
|
const existing = getPredefinedRequestExample(ref);
|
|
62
38
|
if (existing)
|
|
63
39
|
return existing;
|
|
64
|
-
const fieldMetas =
|
|
40
|
+
const fieldMetas = getFieldMetas(ref);
|
|
65
41
|
const example = {};
|
|
66
|
-
const isScalar =
|
|
42
|
+
const isScalar = isGqlScalar(ref);
|
|
67
43
|
if (isScalar)
|
|
68
|
-
return
|
|
44
|
+
return getScalarExample(ref);
|
|
69
45
|
else {
|
|
70
46
|
fieldMetas.forEach((fieldMeta) => {
|
|
71
47
|
if (!fieldMeta.isScalar && fieldMeta.isClass)
|
|
72
48
|
example[fieldMeta.key] = "ObjectID";
|
|
73
49
|
else
|
|
74
|
-
example[fieldMeta.key] = fieldMeta.example ?? fieldMeta.enum ?
|
|
50
|
+
example[fieldMeta.key] = fieldMeta.example ?? fieldMeta.enum ? arraiedModel(fieldMeta.example ?? (fieldMeta.enum?.values)[0], fieldMeta.optArrDepth) : arraiedModel(getRequestExample(fieldMeta.modelRef), fieldMeta.arrDepth);
|
|
75
51
|
});
|
|
76
52
|
}
|
|
77
53
|
Reflect.defineMetadata(ref, example, RequestExampleStorage.prototype);
|
|
78
54
|
return example;
|
|
79
55
|
};
|
|
80
56
|
const makeRequestExample = (sigRef, key) => {
|
|
81
|
-
const [argMetas] =
|
|
57
|
+
const [argMetas] = getArgMetas(sigRef, key);
|
|
82
58
|
return getExampleData(argMetas);
|
|
83
59
|
};
|
|
84
60
|
const getExampleData = (argMetas, signalType = "graphql") => Object.fromEntries(
|
|
85
61
|
argMetas.filter((argMeta) => argMeta.type !== "Upload").map((argMeta) => {
|
|
86
|
-
const [argRef, argArrDepth] =
|
|
62
|
+
const [argRef, argArrDepth] = getNonArrayModel(argMeta.returns());
|
|
87
63
|
const example = argMeta.argsOption.example ?? getRequestExample(argRef);
|
|
88
64
|
return [
|
|
89
65
|
argMeta.name,
|
|
90
|
-
|
|
91
|
-
signalType === "restapi" && argRef.prototype ===
|
|
66
|
+
arraiedModel(
|
|
67
|
+
signalType === "restapi" && argRef.prototype === GqlJSON.prototype ? JSON.stringify(example, null, 2) : example,
|
|
92
68
|
argArrDepth
|
|
93
69
|
)
|
|
94
70
|
];
|
|
95
71
|
})
|
|
96
72
|
);
|
|
97
73
|
const makeResponseExample = (sigRef, key) => {
|
|
98
|
-
const gqlMeta =
|
|
74
|
+
const gqlMeta = getGqlMeta(sigRef, key);
|
|
99
75
|
const example = getResponseExample(gqlMeta.returns());
|
|
100
76
|
return example;
|
|
101
77
|
};
|
|
78
|
+
export {
|
|
79
|
+
getExampleData,
|
|
80
|
+
makeRequestExample,
|
|
81
|
+
makeResponseExample
|
|
82
|
+
};
|