corebasic 1.0.233 → 1.0.235
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/dist/libs/dipper.js +1 -1
- package/dist/libs/messaging.js +1 -1
- package/dist/libs/schemas.js +18 -0
- package/dist/libs/utils.js +4 -0
- package/index.ts +1 -0
- package/libs/dipper.ts +1 -1
- package/libs/kafka.ts +1 -1
- package/libs/messaging.ts +14 -12
- package/libs/schemas.ts +12 -0
- package/libs/utils.ts +5 -0
- package/package.json +1 -1
package/dist/libs/dipper.js
CHANGED
|
@@ -30,7 +30,7 @@ function shard(key) {
|
|
|
30
30
|
}
|
|
31
31
|
export let shard_hits = {};
|
|
32
32
|
async function postDip(url, arg) {
|
|
33
|
-
return (await axios.post(url, arg)).data;
|
|
33
|
+
return (await axios.post(String(url), arg)).data;
|
|
34
34
|
// curl
|
|
35
35
|
// -----
|
|
36
36
|
// const { data } = await curly.post(url, {
|
package/dist/libs/messaging.js
CHANGED
|
@@ -53,7 +53,7 @@ export async function start(app) {
|
|
|
53
53
|
await consumer.connect();
|
|
54
54
|
publisher = createClient({ url });
|
|
55
55
|
await publisher.connect();
|
|
56
|
-
consumer.on('error', err => console.log('Redis Client Error', err));
|
|
56
|
+
consumer.on('error', (err) => console.log('Redis Client Error', err));
|
|
57
57
|
app.get('/messages/:user', async (req, res) => {
|
|
58
58
|
let uid = req.body.client;
|
|
59
59
|
await connect({ user: req.params.user, req, res, uid });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { readdir } from "node:fs/promises";
|
|
10
|
+
import * as Utils from './utils.js';
|
|
11
|
+
const g_this = globalThis;
|
|
12
|
+
g_this.Schemas ??= {};
|
|
13
|
+
for (const file of await readdir(Utils.PROJECT_ROOT_PATH)) {
|
|
14
|
+
if (file.endsWith(".ts") && file !== "index.ts") {
|
|
15
|
+
const schema = await import(__rewriteRelativeImportExtension(`${Utils.PROJECT_ROOT_PATH}/schemas/${file}`));
|
|
16
|
+
Object.assign(g_this.Schemas, schema.Schemas);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/libs/utils.js
CHANGED
|
@@ -7,6 +7,10 @@ export function log(...args) {
|
|
|
7
7
|
const res = args.map(arg => typeof arg === "object" ? JSON.stringify(arg, null, '\t') : arg);
|
|
8
8
|
console.log(...res);
|
|
9
9
|
}
|
|
10
|
+
let PROJECT_ROOT_URL = new URL('../../..', import.meta.url);
|
|
11
|
+
if (String(PROJECT_ROOT_URL).endsWith('node_modules/'))
|
|
12
|
+
PROJECT_ROOT_URL = new URL('..', PROJECT_ROOT_URL);
|
|
13
|
+
export const PROJECT_ROOT_PATH = String(PROJECT_ROOT_URL).endsWith("/") ? String(PROJECT_ROOT_URL).slice(0, -1) : String(PROJECT_ROOT_URL);
|
|
10
14
|
let UID_COUNTER = crypto.randomBytes(3).readUIntBE(0, 3);
|
|
11
15
|
const UID_PROCESS = crypto.randomBytes(5);
|
|
12
16
|
export function uid() {
|
package/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as Auth from './libs/auth.ts'
|
|
|
9
9
|
import * as Features from './libs/features.ts'
|
|
10
10
|
import * as Messaging from './libs/messaging.ts'
|
|
11
11
|
import * as Compression from './libs/compression.ts'
|
|
12
|
+
import * as Sch from './libs/schemas.ts'
|
|
12
13
|
|
|
13
14
|
export {
|
|
14
15
|
Elabase,
|
package/libs/dipper.ts
CHANGED
|
@@ -51,7 +51,7 @@ function shard(key: string) {
|
|
|
51
51
|
export let shard_hits: Record<string, number> = {}
|
|
52
52
|
|
|
53
53
|
async function postDip(url: string | URL, arg: unknown) {
|
|
54
|
-
return (await axios.post(url, arg)).data
|
|
54
|
+
return (await axios.post(String(url), arg)).data
|
|
55
55
|
// curl
|
|
56
56
|
// -----
|
|
57
57
|
// const { data } = await curly.post(url, {
|
package/libs/kafka.ts
CHANGED
package/libs/messaging.ts
CHANGED
|
@@ -10,20 +10,22 @@ const url = process.env.REDIS_URL || "redis://localhost:6380"
|
|
|
10
10
|
|
|
11
11
|
// url: 'redis://alice:foobared@localhost:6380'
|
|
12
12
|
|
|
13
|
+
type RedisConsumer = ReturnType<typeof createClient>;
|
|
14
|
+
type RedisPublisher = ReturnType<typeof createClient>;
|
|
13
15
|
|
|
14
16
|
type RedisListener = (message: string, channel: string) => void
|
|
15
17
|
|
|
16
|
-
type RedisConsumer = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type RedisPublisher = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
18
|
+
// type RedisConsumer = {
|
|
19
|
+
// connect: () => Promise<void>
|
|
20
|
+
// subscribe: (channel: string, listener: RedisListener) => Promise<void>
|
|
21
|
+
// unsubscribe: (channel: string, listener: RedisListener) => Promise<void>
|
|
22
|
+
// on: (event: string, listener: (err: unknown) => void) => void
|
|
23
|
+
// }
|
|
24
|
+
//
|
|
25
|
+
// type RedisPublisher = {
|
|
26
|
+
// connect: () => Promise<void>
|
|
27
|
+
// publish: (channel: string, message: string) => Promise<unknown>
|
|
28
|
+
// }
|
|
27
29
|
|
|
28
30
|
type Request = {
|
|
29
31
|
body: {
|
|
@@ -123,7 +125,7 @@ export async function start(app: ExpressApp) {
|
|
|
123
125
|
publisher = createClient({ url });
|
|
124
126
|
await publisher.connect();
|
|
125
127
|
|
|
126
|
-
consumer.on('error', err => console.log('Redis Client Error', err));
|
|
128
|
+
consumer.on('error', (err: any) => console.log('Redis Client Error', err));
|
|
127
129
|
|
|
128
130
|
app.get('/messages/:user', async (req, res) => {
|
|
129
131
|
let uid = req.body.client
|
package/libs/schemas.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readdir } from "node:fs/promises"
|
|
2
|
+
import * as Utils from './utils.ts'
|
|
3
|
+
|
|
4
|
+
const g_this: any = globalThis as any
|
|
5
|
+
g_this.Schemas ??= {};
|
|
6
|
+
|
|
7
|
+
for (const file of await readdir(Utils.PROJECT_ROOT_PATH)) {
|
|
8
|
+
if (file.endsWith(".ts") && file !== "index.ts") {
|
|
9
|
+
const schema = await import(`${Utils.PROJECT_ROOT_PATH}/schemas/${file}`)
|
|
10
|
+
Object.assign(g_this.Schemas, schema.Schemas)
|
|
11
|
+
}
|
|
12
|
+
}
|
package/libs/utils.ts
CHANGED
|
@@ -11,6 +11,11 @@ export function log(...args: unknown[]): void {
|
|
|
11
11
|
console.log(...res)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
let PROJECT_ROOT_URL = new URL('../../..', import.meta.url)
|
|
15
|
+
if (String(PROJECT_ROOT_URL).endsWith('node_modules/'))
|
|
16
|
+
PROJECT_ROOT_URL = new URL('..', PROJECT_ROOT_URL)
|
|
17
|
+
export const PROJECT_ROOT_PATH: string = String(PROJECT_ROOT_URL).endsWith("/") ? String(PROJECT_ROOT_URL).slice(0, -1) : String(PROJECT_ROOT_URL)
|
|
18
|
+
|
|
14
19
|
|
|
15
20
|
let UID_COUNTER = crypto.randomBytes(3).readUIntBE(0, 3);
|
|
16
21
|
const UID_PROCESS = crypto.randomBytes(5);
|