Skip to content

Commit 4501a47

Browse files
Merge branch 'master' into express-5-8529
2 parents 11f1509 + d50af6c commit 4501a47

Some content is hidden

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

84 files changed

+3815
-401
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,8 @@ src/.claude/settings.local.json
164164

165165
# test reports by jest-junit
166166
junit.xml
167+
*.egg-info
168+
.python-version
169+
170+
# autogenerated docs
171+
**/cocalc-api/site/**

src/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"scripts": {
66
"make": "pnpm run build",
77
"make-dev": "pnpm run build-dev",
8-
"build": "./workspaces.py install && ./workspaces.py build",
9-
"build-dev": "./workspaces.py install && ./workspaces.py build --dev",
8+
"build": "./workspaces.py install && ./workspaces.py build && pnpm python-api",
9+
"build-dev": "./workspaces.py install && ./workspaces.py build --dev && pnpm python-api",
1010
"clean": "rm -rf packages/node_modules && ./workspaces.py clean && cd compute/compute && pnpm clean ",
1111
"hub": "cd packages/hub && npm run hub-project-dev-nobuild",
1212
"hub-prod": "cd packages/hub && npm run hub-project-prod-nobuild",
@@ -24,7 +24,8 @@
2424
"local-ci": "./scripts/ci.sh",
2525
"conat-connections": "cd packages/backend && pnpm conat-connections",
2626
"conat-watch": "cd packages/backend && pnpm conat-watch",
27-
"conat-inventory": "cd packages/backend && pnpm conat-inventory"
27+
"conat-inventory": "cd packages/backend && pnpm conat-inventory",
28+
"python-api": "cd python/cocalc-api && make all"
2829
},
2930
"repository": {
3031
"type": "git",

src/packages/conat/core/client.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,14 +1450,13 @@ export class Client extends EventEmitter {
14501450
sync = {
14511451
dkv: async <T,>(opts: DKVOptions): Promise<DKV<T>> =>
14521452
await dkv<T>({ ...opts, client: this }),
1453-
akv: async <T,>(opts: DKVOptions): Promise<AKV<T>> =>
1454-
await akv<T>({ ...opts, client: this }),
1453+
akv: <T,>(opts: DKVOptions): AKV<T> => akv<T>({ ...opts, client: this }),
14551454
dko: async <T,>(opts: DKVOptions): Promise<DKO<T>> =>
14561455
await dko<T>({ ...opts, client: this }),
14571456
dstream: async <T,>(opts: DStreamOptions): Promise<DStream<T>> =>
14581457
await dstream<T>({ ...opts, client: this }),
1459-
astream: async <T,>(opts: DStreamOptions): Promise<AStream<T>> =>
1460-
await astream<T>({ ...opts, client: this }),
1458+
astream: <T,>(opts: DStreamOptions): AStream<T> =>
1459+
astream<T>({ ...opts, client: this }),
14611460
synctable: async (opts: SyncTableOptions): Promise<ConatSyncTable> =>
14621461
await createSyncTable({ ...opts, client: this }),
14631462
};

src/packages/conat/hub/api/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import { type Projects, projects } from "./projects";
55
import { type DB, db } from "./db";
66
import { type Jupyter, jupyter } from "./jupyter";
77
import { handleErrorMessage } from "@cocalc/conat/util";
8+
import { type Sync, sync } from "./sync";
9+
import { type Org, org } from "./org";
10+
import { type Messages, messages } from "./messages";
811

912
export interface HubApi {
1013
system: System;
1114
projects: Projects;
1215
db: DB;
1316
purchases: Purchases;
1417
jupyter: Jupyter;
18+
sync: Sync;
19+
org: Org;
20+
messages: Messages;
1521
}
1622

1723
const HubApiStructure = {
@@ -20,6 +26,9 @@ const HubApiStructure = {
2026
db,
2127
purchases,
2228
jupyter,
29+
sync,
30+
org,
31+
messages,
2332
} as const;
2433

2534
export function transformArgs({ name, args, account_id, project_id }) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { authFirst } from "./util";
2+
import {
3+
type ApiMessagesGet,
4+
type MessageMe,
5+
} from "@cocalc/util/db-schema/messages";
6+
7+
export interface Messages {
8+
send: (opts: {
9+
account_id?: string;
10+
// to_ids-- account_id's or email addresses of users with accounts
11+
to_ids: string[];
12+
// short plain text formatted subject
13+
subject: string;
14+
// longer markdown formatted body
15+
body: string;
16+
reply_id?: number;
17+
}) => Promise<number>;
18+
19+
get: (opts: ApiMessagesGet) => Promise<MessageMe[]>;
20+
}
21+
22+
export const messages = {
23+
send: authFirst,
24+
get: authFirst,
25+
};

src/packages/conat/hub/api/org.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { authFirst } from "./util";
2+
3+
export const org = {
4+
getAll: authFirst,
5+
create: authFirst,
6+
get: authFirst,
7+
set: authFirst,
8+
addAdmin: authFirst,
9+
addUser: authFirst,
10+
createUser: authFirst,
11+
createToken: authFirst,
12+
expireToken: authFirst,
13+
getUsers: authFirst,
14+
message: authFirst,
15+
removeUser: authFirst,
16+
removeAdmin: authFirst,
17+
};
18+
19+
export interface Org {
20+
// get every organization that the given account is a member or admin of. If account_id is a site
21+
// admin, this gets all organizations, and status will usually be 'none' in that case.
22+
getAll: (opts: { account_id?: string }) => Promise<
23+
{
24+
name: string;
25+
title?: string;
26+
admin_account_ids?: string[];
27+
}[]
28+
>;
29+
30+
// create a new organization with the given unique name (at most 39 characters); only admins
31+
// can create an organization. Returns uuid of organization. The name CANNOT BE CHANGED,
32+
// because it is what is used elsewhere to link to the org.
33+
create: (opts: { account_id?: string; name: string }) => Promise<string>;
34+
35+
// get properties of an existing organization
36+
get: (opts: { account_id?: string; name: string }) => Promise<{
37+
name: string;
38+
title?: string;
39+
description?: string;
40+
link?: string;
41+
email_address?: string;
42+
admin_account_ids?: string[];
43+
}>;
44+
45+
// change properties of an existing organization
46+
set: (opts: {
47+
account_id?: string;
48+
name: string;
49+
title?: string;
50+
description?: string;
51+
link?: string;
52+
email_address?: string;
53+
}) => Promise<void>;
54+
55+
addAdmin: (opts: {
56+
account_id?: string;
57+
name: string;
58+
// user = account_id or email address
59+
user: string;
60+
}) => Promise<void>;
61+
62+
addUser: (opts: {
63+
account_id?: string;
64+
name: string;
65+
// user = account_id or email address
66+
user: string;
67+
}) => Promise<void>;
68+
69+
createUser: (opts: {
70+
account_id?: string;
71+
name: string;
72+
email: string;
73+
firstName: string;
74+
lastName: string;
75+
password: string;
76+
}) => Promise<string>;
77+
78+
removeUser: (opts: {
79+
account_id?: string;
80+
name: string;
81+
// user = account_id or email address
82+
user: string;
83+
}) => Promise<void>;
84+
85+
removeAdmin: (opts: {
86+
account_id?: string;
87+
name: string;
88+
// user = account_id or email address
89+
user: string;
90+
}) => Promise<void>;
91+
92+
createToken: (opts: {
93+
account_id?: string;
94+
// user = account_id or email address
95+
user: string;
96+
}) => Promise<{ token: string; url: string }>;
97+
98+
expireToken: (opts: { account_id?: string; token: string }) => Promise<void>;
99+
100+
getUsers: (opts: { account_id?: string; name: string }) => Promise<
101+
{
102+
first_name: string;
103+
last_name: string;
104+
account_id: string;
105+
email_address: string;
106+
}[]
107+
>;
108+
109+
message: (opts: {
110+
account_id?: string;
111+
name: string;
112+
subject: string;
113+
body: string;
114+
}) => Promise<void>;
115+
}

src/packages/conat/hub/api/projects.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const projects = {
1010
inviteCollaborator: authFirstRequireAccount,
1111
inviteCollaboratorWithoutAccount: authFirstRequireAccount,
1212
setQuotas: authFirstRequireAccount,
13+
start: authFirstRequireAccount,
14+
stop: authFirstRequireAccount,
1315
};
1416

1517
export type AddCollaborator =
@@ -98,4 +100,7 @@ export interface Projects {
98100
member_host?: number;
99101
always_running?: number;
100102
}) => Promise<void>;
103+
104+
start: (opts: { account_id: string; project_id: string }) => Promise<void>;
105+
stop: (opts: { account_id: string; project_id: string }) => Promise<void>;
101106
}

src/packages/conat/hub/api/sync.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { authFirst } from "./util";
2+
3+
export interface Patch {
4+
seq: number;
5+
time: number;
6+
mesg: {
7+
time: number;
8+
wall: number;
9+
patch: string;
10+
user_id: number;
11+
is_snapshot?: boolean;
12+
parents: number[];
13+
version?: number;
14+
};
15+
}
16+
17+
export interface HistoryInfo {
18+
doctype: string;
19+
init: { time: Date; size: number; error: string };
20+
last_active: Date;
21+
path: string;
22+
project_id: string;
23+
read_only: boolean;
24+
save: {
25+
state: string;
26+
error: string;
27+
hash: number;
28+
time: number;
29+
expected_hash: number;
30+
};
31+
string_id: string;
32+
users: string[];
33+
}
34+
35+
export interface Sync {
36+
history: (opts: {
37+
account_id?: string;
38+
project_id: string;
39+
path: string;
40+
}) => Promise<{ patches: Patch[] }>;
41+
}
42+
43+
export const sync = {
44+
history: authFirst,
45+
};

src/packages/conat/hub/changefeeds/util.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ export const SUBJECT = "changefeeds.*";
66
// If the user refreshes their browser, it is still about a minute
77
// before all the changefeeds they had open are free (due to the
88
// SERVER_KEEPALIVE time below).
9-
export const MAX_PER_ACCOUNT = 500;
10-
export const MAX_GLOBAL = 10000;
9+
export const MAX_PER_ACCOUNT = 1_000;
10+
export const MAX_GLOBAL = 50_000;
1111

1212
const DEBUG_DEVEL_MODE = false;
1313

14-
export let CLIENT_KEEPALIVE = 90000;
15-
export let SERVER_KEEPALIVE = 45000;
16-
export let KEEPALIVE_TIMEOUT = 10000;
14+
export let CLIENT_KEEPALIVE = 90_000;
15+
export let SERVER_KEEPALIVE = 45_000;
16+
export let KEEPALIVE_TIMEOUT = 15_000;
1717

1818
if (DEBUG_DEVEL_MODE) {
1919
console.log(
20-
"*** WARNING: Using DEBUB_DEVEL_MODE changefeed parameters!! ***",
20+
"*** WARNING: Using DEBUG_DEVEL_MODE changefeed parameters!! ***",
2121
);
2222
CLIENT_KEEPALIVE = 6000;
2323
SERVER_KEEPALIVE = 3000;

src/packages/conat/package.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,11 @@
2222
"clean": "rm -rf dist node_modules",
2323
"tsc": "pnpm exec tsc --watch --pretty --preserveWatchOutput",
2424
"test": "pnpm exec jest",
25-
"depcheck": "pnpx depcheck --ignores events"
25+
"depcheck": "pnpx depcheck --ignores events,bufferutil,utf-8-validate"
2626
},
27-
"files": [
28-
"dist/**",
29-
"README.md",
30-
"package.json"
31-
],
27+
"files": ["dist/**", "README.md", "package.json"],
3228
"author": "SageMath, Inc.",
33-
"keywords": [
34-
"utilities",
35-
"conat",
36-
"cocalc"
37-
],
29+
"keywords": ["utilities", "conat", "cocalc"],
3830
"license": "SEE LICENSE.md",
3931
"dependencies": {
4032
"@cocalc/comm": "workspace:*",
@@ -44,6 +36,7 @@
4436
"@msgpack/msgpack": "^3.1.1",
4537
"ascii-table3": "^1.0.1",
4638
"awaiting": "^3.0.0",
39+
"bufferutil": "^4.0.9",
4740
"consistent-hash": "^1.2.2",
4841
"dayjs": "^1.11.11",
4942
"events": "3.3.0",
@@ -52,7 +45,8 @@
5245
"json-stable-stringify": "^1.0.1",
5346
"lodash": "^4.17.21",
5447
"socket.io": "^4.8.1",
55-
"socket.io-client": "^4.8.1"
48+
"socket.io-client": "^4.8.1",
49+
"utf-8-validate": "^6.0.5"
5650
},
5751
"devDependencies": {
5852
"@types/better-sqlite3": "^7.6.13",

0 commit comments

Comments
 (0)