Skip to content

Commit c69231d

Browse files
authored
feat: add multitenant support (#27)
1 parent 9566ede commit c69231d

File tree

194 files changed

+4646
-2300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+4646
-2300
lines changed

cli/incloud.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { InLog } from "~/in-log/in-log.ts";
2-
import { RunManager } from "./src/run-manager.ts";
32
import convertString from "~/utils/convert-string.ts";
43
import { center } from "~/terminal/format-utils.ts";
4+
import { RunManager } from "#cli/run-manager.ts";
55

66
const inLog = new InLog({
77
consoleDefaultStyle: "full",

cli/src/config-types.ts

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
1-
export type ORMConfig = {
2-
autoTypes: boolean;
3-
autoMigrate: boolean;
4-
embeddedDb: boolean;
5-
embeddedDbPort: number;
6-
ormDebugMode: boolean;
7-
dbConnectionType: "tcp" | "socket";
8-
dbSocketPath: string;
9-
dbName: string;
10-
dbHost: string;
11-
dbPort: number;
12-
dbUser: string;
13-
dbPassword: string;
14-
dbSchema: string;
15-
dbAppName: string;
16-
dbClientMode: "pool" | "single";
17-
dbPoolSize: number;
18-
dbMaxPoolSize: number;
19-
dbIdleTimeout: number;
20-
};
21-
export type AuthConfig = {
22-
allowAll: boolean;
23-
};
24-
25-
export type CloudConfig = {
26-
name: string;
27-
cloudMode: "production" | "development";
28-
logLevel: "info" | "debug" | "error" | "warn";
29-
logTrace: boolean;
30-
brokerPort: number;
31-
queuePort: number;
32-
hostName: string;
33-
port: number;
34-
autoConfig: boolean;
35-
allowedOrigins: Set<string>;
36-
publicRoot: string;
37-
singlePageApp: boolean;
38-
cacheStatic: boolean;
39-
};
1+
import type { CoreConfig } from "~/extension/core-config.ts";
402

413
export interface BuiltInConfig {
42-
cloud: CloudConfig;
43-
orm: ORMConfig;
44-
auth: AuthConfig;
4+
core: CoreConfig;
455
}

cli/src/multicore.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
* **Note:** This function is currently only implemented for Linux systems.
55
* If you are using a different OS, it will return 1.
66
*/
7-
export async function getCoreCount(): Promise<number> {
7+
export async function getCoreCount(
8+
config?: { single?: boolean },
9+
): Promise<number> {
10+
const { single = false } = config || {};
11+
if (single) return 1;
812
if (Deno.build.os !== "linux") {
913
return 1;
1014
}

cli/src/run-manager.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ const inLogSmall = new InLog({
1010
});
1111
import { makeLogo } from "~/terminal/logo.ts";
1212
import { InLog } from "~/in-log/in-log.ts";
13-
import { getCoreCount } from "./multicore.ts";
14-
import { loadCloudConfigFile } from "./cloud-config.ts";
13+
import { getCoreCount } from "#cli/multicore.ts";
14+
import { loadCloudConfigFile } from "#cli/cloud-config.ts";
1515
import convertString from "~/utils/convert-string.ts";
1616
import { joinPath } from "~/utils/path-utils.ts";
1717
import { center } from "~/terminal/format-utils.ts";
1818
import ColorMe from "~/terminal/color-me.ts";
19-
import type { RunnerMode } from "./types.ts";
19+
import type { RunnerMode } from "#cli/types.ts";
2020

2121
const logo = makeLogo({
2222
symbol: "alt2DownLeft",
@@ -53,7 +53,7 @@ export class RunManager {
5353
this.appName = Deno.env.get("APP_NAME") || "InSpatial";
5454
}
5555
async init(): Promise<void> {
56-
this.coreCount = await getCoreCount();
56+
this.coreCount = await getCoreCount({ single: true }); // skip multicore at the moment
5757
await this.spawnInit();
5858
const result = loadCloudConfigFile(this.rootPath);
5959
if (!result) {
@@ -65,14 +65,23 @@ export class RunManager {
6565
}
6666
const { config, env } = result;
6767
this.env = env;
68-
const { hostName, port, brokerPort, queuePort, cloudMode, name } =
69-
config.cloud;
68+
const {
69+
hostName,
70+
port,
71+
brokerPort,
72+
queuePort,
73+
cloudMode,
74+
name,
75+
embeddedDb,
76+
embeddedDbPort,
77+
autoTypes,
78+
autoMigrate,
79+
} = config.core;
7080
this.appName = name || this.appName;
7181
this.appTitle = convertString(this.appName, "title", true);
7282
if (cloudMode == "development") {
7383
this.watch = true;
7484
}
75-
const { embeddedDb, embeddedDbPort, autoTypes, autoMigrate } = config.orm;
7685

7786
this.autoMigrate = autoMigrate;
7887
this.autoTypes = autoTypes;
@@ -101,7 +110,7 @@ export class RunManager {
101110
}
102111
if (!embeddedDb) {
103112
dbConnectionString = makeDBConnectionString(
104-
config.orm,
113+
config.core,
105114
);
106115
}
107116
const rows = [
@@ -123,7 +132,6 @@ export class RunManager {
123132
);
124133
this.setupWatcher();
125134
}
126-
// Terminal.showCursor();
127135
}
128136
async setupWatcher() {
129137
const dirs = Deno.readDirSync(this.rootPath);

cli/src/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export async function allowPortBinding() {
2+
if (Deno.build.os !== "linux") {
3+
throw new Error("This function is only supported on Linux");
4+
}
5+
6+
const cmd = new Deno.Command("sudo", {
7+
args: ["setcap", "cap_net_bind_service=+ep", Deno.execPath()],
8+
stderr: "piped",
9+
});
10+
const child = cmd.spawn();
11+
const output = await child.output();
12+
13+
if (output.code !== 0) {
14+
throw new Error(new TextDecoder().decode(output.stderr));
15+
}
16+
return output.code;
17+
}

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inspatial/cloud",
3-
"version": "0.4.1",
3+
"version": "0.5.0",
44
"license": "Apache-2.0",
55
"exports": {
66
".": "./mod.ts",
@@ -26,6 +26,7 @@
2626
},
2727
"imports": {
2828
"~/": "./src/",
29+
"#cli/": "./cli/src/",
2930
"#extensions/": "./extensions/",
3031
"#types/": "./src/types/",
3132
"#inLog": "./src/in-log/in-log.ts"

extensions/auth/auth-group.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

extensions/auth/boot/checkForUser.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

extensions/auth/config.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

extensions/auth/mod.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)