orez 0.5.30 → 0.5.34
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/cf-do/application-sql.d.ts +6 -9
- package/dist/cf-do/application-sql.d.ts.map +1 -1
- package/dist/cf-do/application-sql.js +5 -14
- package/dist/cf-do/application-sql.js.map +1 -1
- package/dist/cf-do/cursor-pull.js +2 -2
- package/dist/cf-do/cursor-pull.js.map +1 -1
- package/dist/cf-do/worker.d.ts +6 -11
- package/dist/cf-do/worker.d.ts.map +1 -1
- package/dist/cf-do/worker.js +7 -14
- package/dist/cf-do/worker.js.map +1 -1
- package/dist/sync-browser-host/generated/sync_wasm_bg.wasm +0 -0
- package/dist/sync-browser-host/host.d.ts +3 -2
- package/dist/sync-browser-host/host.d.ts.map +1 -1
- package/dist/sync-browser-host/host.js +107 -87
- package/dist/sync-browser-host/host.js.map +1 -1
- package/dist/sync-browser-host/idb-snapshot.d.ts +1 -0
- package/dist/sync-browser-host/idb-snapshot.d.ts.map +1 -1
- package/dist/sync-browser-host/idb-snapshot.js +13 -0
- package/dist/sync-browser-host/idb-snapshot.js.map +1 -1
- package/dist/sync-browser-host/index.d.ts +2 -1
- package/dist/sync-browser-host/index.d.ts.map +1 -1
- package/dist/sync-browser-host/index.js +2 -1
- package/dist/sync-browser-host/index.js.map +1 -1
- package/dist/sync-browser-host/message-port.d.ts +3 -2
- package/dist/sync-browser-host/message-port.d.ts.map +1 -1
- package/dist/sync-browser-host/message-port.js.map +1 -1
- package/dist/sync-browser-host/sqlite-adapter.d.ts +5 -4
- package/dist/sync-browser-host/sqlite-adapter.d.ts.map +1 -1
- package/dist/sync-browser-host/sqlite-adapter.js.map +1 -1
- package/dist/sync-browser-host/types.d.ts +14 -58
- package/dist/sync-browser-host/types.d.ts.map +1 -1
- package/dist/sync-browser-host/types.js +1 -4
- package/dist/sync-browser-host/types.js.map +1 -1
- package/dist/sync-cf-host.d.ts +2 -0
- package/dist/sync-cf-host.d.ts.map +1 -0
- package/dist/sync-cf-host.js +2 -0
- package/dist/sync-cf-host.js.map +1 -0
- package/dist/sync-executor.d.ts +2 -0
- package/dist/sync-executor.d.ts.map +1 -0
- package/dist/sync-executor.js +2 -0
- package/dist/sync-executor.js.map +1 -0
- package/dist/zero-http/encrypted-column-codec.d.ts +46 -0
- package/dist/zero-http/encrypted-column-codec.d.ts.map +1 -0
- package/dist/zero-http/encrypted-column-codec.js +676 -0
- package/dist/zero-http/encrypted-column-codec.js.map +1 -0
- package/dist/zero-http/encrypted-column-conformance.d.ts +7 -0
- package/dist/zero-http/encrypted-column-conformance.d.ts.map +1 -0
- package/dist/zero-http/encrypted-column-conformance.js +161 -0
- package/dist/zero-http/encrypted-column-conformance.js.map +1 -0
- package/dist/zero-http/mount.d.ts +50 -0
- package/dist/zero-http/mount.d.ts.map +1 -0
- package/dist/zero-http/mount.js +323 -0
- package/dist/zero-http/mount.js.map +1 -0
- package/dist/zero-http/payload-codec.d.ts +91 -0
- package/dist/zero-http/payload-codec.d.ts.map +1 -0
- package/dist/zero-http/payload-codec.js +10 -0
- package/dist/zero-http/payload-codec.js.map +1 -0
- package/dist/zero-http/server.d.ts +7 -5
- package/dist/zero-http/server.d.ts.map +1 -1
- package/dist/zero-http/server.js +172 -248
- package/dist/zero-http/server.js.map +1 -1
- package/dist/zero-http/transport.d.ts +3 -0
- package/dist/zero-http/transport.d.ts.map +1 -1
- package/dist/zero-http/transport.js +28 -8
- package/dist/zero-http/transport.js.map +1 -1
- package/package.json +34 -13
- package/dist/sync-server/sync-server.d.ts +0 -121
- package/dist/sync-server/sync-server.d.ts.map +0 -1
- package/dist/sync-server/sync-server.js +0 -413
- package/dist/sync-server/sync-server.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount.js","sourceRoot":"","sources":["../../src/zero-http/mount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAyBvD,M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
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export type JSONPrimitive = null | boolean | number | string;
|
|
2
|
+
export type JSONValue = JSONPrimitive | readonly JSONValue[] | {
|
|
3
|
+
readonly [key: string]: JSONValue;
|
|
4
|
+
};
|
|
5
|
+
export type JSONObject = Readonly<Record<string, JSONValue>>;
|
|
6
|
+
export type PushMutation = JSONObject & {
|
|
7
|
+
readonly type: string;
|
|
8
|
+
readonly clientID: string;
|
|
9
|
+
readonly id: number;
|
|
10
|
+
readonly name?: string;
|
|
11
|
+
readonly args?: readonly JSONValue[];
|
|
12
|
+
};
|
|
13
|
+
export type PushRequest = JSONObject & {
|
|
14
|
+
readonly mutations: readonly PushMutation[];
|
|
15
|
+
};
|
|
16
|
+
export type GotQueryPatchOp = {
|
|
17
|
+
readonly op: 'clear';
|
|
18
|
+
} | {
|
|
19
|
+
readonly op: 'put' | 'del';
|
|
20
|
+
readonly hash: string;
|
|
21
|
+
};
|
|
22
|
+
export type ServerGotQueries = {
|
|
23
|
+
readonly version: number;
|
|
24
|
+
readonly patch: readonly GotQueryPatchOp[];
|
|
25
|
+
};
|
|
26
|
+
export type PullResponse = {
|
|
27
|
+
readonly [key: string]: JSONValue | undefined;
|
|
28
|
+
readonly cookie: number;
|
|
29
|
+
readonly lastMutationIDChanges: Readonly<Record<string, number>>;
|
|
30
|
+
readonly rowsPatch: readonly JSONValue[];
|
|
31
|
+
readonly unchanged?: false;
|
|
32
|
+
readonly gotQueries?: ServerGotQueries;
|
|
33
|
+
} | {
|
|
34
|
+
readonly [key: string]: JSONValue | undefined;
|
|
35
|
+
readonly cookie: number | null;
|
|
36
|
+
readonly unchanged: true;
|
|
37
|
+
readonly gotQueries?: ServerGotQueries;
|
|
38
|
+
};
|
|
39
|
+
export interface PayloadCodec {
|
|
40
|
+
/** stable configuration identity used to detect conflicting transports. */
|
|
41
|
+
readonly id: string;
|
|
42
|
+
/** called exactly once for each serialized /push attempt. */
|
|
43
|
+
encodePush(body: PushRequest): Promise<PushRequest>;
|
|
44
|
+
/** called for every successful /pull response before any poke is emitted. */
|
|
45
|
+
decodePull(response: PullResponse): Promise<PullResponse>;
|
|
46
|
+
}
|
|
47
|
+
export type EncryptedColumnManifest = {
|
|
48
|
+
readonly version: 1;
|
|
49
|
+
readonly networkID: string;
|
|
50
|
+
readonly schemaID: string;
|
|
51
|
+
readonly rowMutations: Readonly<Record<string, {
|
|
52
|
+
readonly argumentIndex: number;
|
|
53
|
+
readonly format: 'orez-row-batch-v1';
|
|
54
|
+
}>>;
|
|
55
|
+
readonly tables: Readonly<Record<string, {
|
|
56
|
+
readonly serverName?: string;
|
|
57
|
+
readonly primaryKey: readonly string[];
|
|
58
|
+
/** physical names for renamed primary-key columns. */
|
|
59
|
+
readonly primaryKeyServerNames?: Readonly<Record<string, string>>;
|
|
60
|
+
readonly columns: Readonly<Record<string, {
|
|
61
|
+
readonly serverName?: string;
|
|
62
|
+
}>>;
|
|
63
|
+
}>>;
|
|
64
|
+
};
|
|
65
|
+
export type EncryptedRowBatch = {
|
|
66
|
+
readonly sourceID: string;
|
|
67
|
+
readonly fromSeq: number;
|
|
68
|
+
readonly throughSeq: number;
|
|
69
|
+
readonly rows: readonly ({
|
|
70
|
+
readonly seq: number;
|
|
71
|
+
readonly op: 'put';
|
|
72
|
+
readonly table: string;
|
|
73
|
+
readonly value: JSONObject;
|
|
74
|
+
} | {
|
|
75
|
+
readonly seq: number;
|
|
76
|
+
readonly op: 'del';
|
|
77
|
+
readonly table: string;
|
|
78
|
+
readonly key: JSONObject;
|
|
79
|
+
})[];
|
|
80
|
+
};
|
|
81
|
+
export interface EncryptionKeyring {
|
|
82
|
+
/** current writable epoch and its 32-byte network content key. */
|
|
83
|
+
current(): Promise<{
|
|
84
|
+
readonly epoch: number;
|
|
85
|
+
readonly key: Uint8Array;
|
|
86
|
+
} | undefined>;
|
|
87
|
+
/** key for a readable current or historical epoch, or undefined. */
|
|
88
|
+
get(epoch: number): Promise<Uint8Array | undefined>;
|
|
89
|
+
}
|
|
90
|
+
export declare const identityPayloadCodec: PayloadCodec;
|
|
91
|
+
//# sourceMappingURL=payload-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-codec.d.ts","sourceRoot":"","sources":["../../src/zero-http/payload-codec.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;AAE5D,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,SAAS,SAAS,EAAE,GACpB;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAEzC,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;AAE5D,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,SAAS,EAAE,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG;IACrC,QAAQ,CAAC,SAAS,EAAE,SAAS,YAAY,EAAE,CAAA;CAC5C,CAAA;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;CAAE,GACxB;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,GAAG,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEzD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,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AE,UAAU,CAAA;KAAE,GAAG,SAAS,CAAC,CAAA;IAEpF,oEAAoE;IACpE,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;CACpD;AAED,eAAO,MAAM,oBAAoB,EAAE,YAQjC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-codec.js","sourceRoot":"","sources":["../../src/zero-http/payload-codec.ts"],"names":[],"mappings":"AAuHA,MAAM,CAAC,MAAM,oBAAoB,GAAiB,MAAM,CAAC,MAAM,CAAC;IAC9D,EAAE,EAAE,kBAAkB;IACtB,KAAK,CAAC,UAAU,CAAC,IAAiB;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,QAAsB;QACrC,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export type Row = Record<string, string>;
|
|
2
|
+
type Seed = {
|
|
3
|
+
user?: Row[];
|
|
4
|
+
project?: Row[];
|
|
5
|
+
member?: Row[];
|
|
6
|
+
};
|
|
2
7
|
export declare function startZeroHttpServer(opts?: {
|
|
3
|
-
seed?:
|
|
4
|
-
user?: Row[];
|
|
5
|
-
project?: Row[];
|
|
6
|
-
member?: Row[];
|
|
7
|
-
};
|
|
8
|
+
seed?: Seed;
|
|
8
9
|
}): Promise<{
|
|
9
10
|
url: string;
|
|
10
11
|
version(): number;
|
|
11
12
|
rows(table: string): Row[];
|
|
12
13
|
close(): Promise<void>;
|
|
13
14
|
}>;
|
|
15
|
+
export {};
|
|
14
16
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/zero-http/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/zero-http/server.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAGxC,KAAK,IAAI,GAAG;IAAE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAA;CAAE,CAAA;AA8F7D,wBAAsB,mBAAmB,CAAC,IAAI,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC;IACzE,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,IAAI,MAAM,CAAA;IACjB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,CAAA;IAC1B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB,CAAC,CAqGD"}
|
package/dist/zero-http/server.js
CHANGED
|
@@ -1,101 +1,159 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
3
|
+
import { MutationApplicationError } from 'orez-sync-executor';
|
|
4
|
+
import { zeroHttpFixtureSchema } from './fixture-schema.js';
|
|
5
|
+
import { createZeroHttpApplicationDatabase, createZeroHttpSyncServer, } from './mount.js';
|
|
6
|
+
const tables = {
|
|
4
7
|
user: {
|
|
5
|
-
|
|
8
|
+
physical: 'user_record',
|
|
6
9
|
columns: { id: 'user_id', name: 'display_name' },
|
|
7
10
|
},
|
|
8
11
|
project: {
|
|
9
|
-
|
|
12
|
+
physical: 'project_record',
|
|
10
13
|
columns: { id: 'project_id', ownerId: 'owner_id', name: 'project_name' },
|
|
11
14
|
},
|
|
12
15
|
member: {
|
|
13
|
-
|
|
16
|
+
physical: 'project_member',
|
|
14
17
|
columns: { id: 'member_id', projectId: 'project_id', userId: 'user_id' },
|
|
15
18
|
},
|
|
16
19
|
};
|
|
20
|
+
function createDatabase(sqlite) {
|
|
21
|
+
return {
|
|
22
|
+
exec(sql, params = []) {
|
|
23
|
+
sqlite.prepare(sql).run(...params);
|
|
24
|
+
},
|
|
25
|
+
all(sql, params = []) {
|
|
26
|
+
return sqlite.prepare(sql).all(...params);
|
|
27
|
+
},
|
|
28
|
+
transaction(work) {
|
|
29
|
+
sqlite.exec('BEGIN');
|
|
30
|
+
try {
|
|
31
|
+
const result = work();
|
|
32
|
+
sqlite.exec('COMMIT');
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
sqlite.exec('ROLLBACK');
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function createMutators() {
|
|
43
|
+
return {
|
|
44
|
+
'project|create': async ({ tx, args, ctx }) => {
|
|
45
|
+
const value = args;
|
|
46
|
+
if (value.ownerId !== ctx.claims.userID) {
|
|
47
|
+
throw new MutationApplicationError('forbidden');
|
|
48
|
+
}
|
|
49
|
+
await tx.mutate.project.insert(value);
|
|
50
|
+
},
|
|
51
|
+
'project|rename': async ({ tx, args, ctx }) => {
|
|
52
|
+
const value = args;
|
|
53
|
+
const rows = Array.from(await tx.dbTransaction.query('SELECT owner_id AS ownerID FROM project_record WHERE project_id = ?', [value.id]));
|
|
54
|
+
if (rows.length === 0)
|
|
55
|
+
throw new MutationApplicationError('not-found');
|
|
56
|
+
if (rows[0].ownerID !== ctx.claims.userID) {
|
|
57
|
+
throw new MutationApplicationError('forbidden');
|
|
58
|
+
}
|
|
59
|
+
await tx.mutate.project.update(value);
|
|
60
|
+
},
|
|
61
|
+
'member|add': async ({ tx, args, ctx }) => {
|
|
62
|
+
const value = args;
|
|
63
|
+
const rows = Array.from(await tx.dbTransaction.query('SELECT project_id FROM project_record WHERE project_id = ? AND owner_id = ?', [value.projectId, ctx.claims.userID]));
|
|
64
|
+
if (rows.length === 0)
|
|
65
|
+
throw new MutationApplicationError('forbidden');
|
|
66
|
+
await tx.mutate.member.insert(value);
|
|
67
|
+
},
|
|
68
|
+
'member|remove': async ({ tx, args, ctx }) => {
|
|
69
|
+
const value = args;
|
|
70
|
+
const members = Array.from(await tx.dbTransaction.query('SELECT project_id AS projectId FROM project_member WHERE member_id = ?', [value.id]));
|
|
71
|
+
if (members.length === 0)
|
|
72
|
+
throw new MutationApplicationError('not-found');
|
|
73
|
+
const projects = Array.from(await tx.dbTransaction.query('SELECT project_id FROM project_record WHERE project_id = ? AND owner_id = ?', [members[0].projectId, ctx.claims.userID]));
|
|
74
|
+
if (projects.length === 0)
|
|
75
|
+
throw new MutationApplicationError('forbidden');
|
|
76
|
+
await tx.mutate.member.delete(value);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
17
80
|
export async function startZeroHttpServer(opts) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
81
|
+
const sqlite = new DatabaseSync(':memory:');
|
|
82
|
+
initializeApplicationTables(sqlite, opts?.seed);
|
|
83
|
+
const db = createDatabase(sqlite);
|
|
84
|
+
const sync = createZeroHttpSyncServer({
|
|
85
|
+
applicationDatabase: createZeroHttpApplicationDatabase(db),
|
|
86
|
+
db,
|
|
87
|
+
schema: zeroHttpFixtureSchema,
|
|
88
|
+
tables: {
|
|
89
|
+
user: { columns: { id: 'string', name: 'string' }, primaryKey: ['id'] },
|
|
90
|
+
project: {
|
|
91
|
+
columns: { id: 'string', ownerId: 'string', name: 'string' },
|
|
92
|
+
primaryKey: ['id'],
|
|
93
|
+
},
|
|
94
|
+
member: {
|
|
95
|
+
columns: { id: 'string', projectId: 'string', userId: 'string' },
|
|
96
|
+
primaryKey: ['id'],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
mutators: createMutators(),
|
|
100
|
+
visible(table, userID) {
|
|
101
|
+
if (table === 'user') {
|
|
102
|
+
return {
|
|
103
|
+
sql: 'SELECT * FROM user_record WHERE user_id = ?',
|
|
104
|
+
params: [userID],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (table === 'project') {
|
|
108
|
+
return {
|
|
109
|
+
sql: `SELECT DISTINCT p.* FROM project_record p
|
|
110
|
+
LEFT JOIN project_member m ON m.project_id = p.project_id
|
|
111
|
+
WHERE p.owner_id = ? OR m.user_id = ?`,
|
|
112
|
+
params: [userID, userID],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
sql: `SELECT DISTINCT m.* FROM project_member m
|
|
117
|
+
JOIN project_record p ON p.project_id = m.project_id
|
|
118
|
+
LEFT JOIN project_member viewer ON viewer.project_id = p.project_id
|
|
119
|
+
WHERE p.owner_id = ? OR viewer.user_id = ?`,
|
|
120
|
+
params: [userID, userID],
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
await sync.ready();
|
|
23
125
|
const server = createServer(async (req, res) => {
|
|
24
126
|
try {
|
|
25
127
|
if (req.method !== 'POST') {
|
|
26
128
|
sendJSON(res, 404, { error: 'not found' });
|
|
27
129
|
return;
|
|
28
130
|
}
|
|
29
|
-
const
|
|
30
|
-
const userID = authenticate(req, tables);
|
|
131
|
+
const userID = authenticate(req, sqlite);
|
|
31
132
|
if (!userID) {
|
|
32
133
|
sendJSON(res, 401, { error: 'unauthorized' });
|
|
33
134
|
return;
|
|
34
135
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (body.cookie === cookie) {
|
|
42
|
-
sendJSON(res, 200, { cookie, unchanged: true });
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (typeof body.cookie === 'number' && body.cookie > cookie) {
|
|
46
|
-
sendJSON(res, 409, {
|
|
47
|
-
error: `future cookie ${body.cookie} is ahead of server cookie ${cookie}`,
|
|
48
|
-
});
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
sendJSON(res, 200, {
|
|
52
|
-
cookie,
|
|
53
|
-
lastMutationIDChanges: lastMutationIDChanges(lmids, body.clientGroupID),
|
|
54
|
-
rowsPatch: [{ op: 'clear' }, ...visibleRowsPatch(tables, userID)],
|
|
55
|
-
});
|
|
136
|
+
const path = new URL(req.url || '/', 'http://127.0.0.1').pathname;
|
|
137
|
+
const body = await readJSON(req);
|
|
138
|
+
if (path === '/push') {
|
|
139
|
+
sendJSON(res, 200, await sync.handlePush(body, { userID }));
|
|
56
140
|
return;
|
|
57
141
|
}
|
|
58
|
-
if (path === '/
|
|
59
|
-
|
|
60
|
-
if (!bindClientGroup(clientGroupUsers, body.clientGroupID, userID)) {
|
|
61
|
-
sendJSON(res, 403, { error: 'client group belongs to a different user' });
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const mutations = Array.isArray(body.mutations) ? body.mutations : [];
|
|
65
|
-
const gap = findMutationGap(lmids, body.clientGroupID, mutations);
|
|
66
|
-
if (gap) {
|
|
67
|
-
sendJSON(res, 500, { error: gap });
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const pushResults = [];
|
|
71
|
-
let processedNewMutation = false;
|
|
72
|
-
for (const mutation of mutations) {
|
|
73
|
-
const current = lmidFor(lmids, body.clientGroupID, mutation.clientID);
|
|
74
|
-
if (mutation.id <= current) {
|
|
75
|
-
pushResults.push({
|
|
76
|
-
id: { clientID: mutation.clientID, id: mutation.id },
|
|
77
|
-
result: resultForMutation(mutationResults, body.clientGroupID, mutation.clientID, mutation.id) || {},
|
|
78
|
-
});
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const result = applyMutation(tables, userID, mutation);
|
|
82
|
-
setLMID(lmids, body.clientGroupID, mutation.clientID, mutation.id);
|
|
83
|
-
setMutationResult(mutationResults, body.clientGroupID, mutation.clientID, mutation.id, result);
|
|
84
|
-
processedNewMutation = true;
|
|
85
|
-
pushResults.push({
|
|
86
|
-
id: { clientID: mutation.clientID, id: mutation.id },
|
|
87
|
-
result,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
if (processedNewMutation)
|
|
91
|
-
cookie += 1;
|
|
92
|
-
sendJSON(res, 200, { pushResponse: { mutations: pushResults } });
|
|
142
|
+
if (path === '/pull') {
|
|
143
|
+
sendJSON(res, 200, await sync.handlePull(body, { userID }));
|
|
93
144
|
return;
|
|
94
145
|
}
|
|
95
146
|
sendJSON(res, 404, { error: 'not found' });
|
|
96
147
|
}
|
|
97
|
-
catch (
|
|
98
|
-
|
|
148
|
+
catch (error) {
|
|
149
|
+
const status = typeof error === 'object' && error !== null && 'status' in error
|
|
150
|
+
? Number(error.status)
|
|
151
|
+
: error instanceof SyntaxError
|
|
152
|
+
? 400
|
|
153
|
+
: 500;
|
|
154
|
+
sendJSON(res, status, {
|
|
155
|
+
error: error instanceof Error ? error.message : String(error),
|
|
156
|
+
});
|
|
99
157
|
}
|
|
100
158
|
});
|
|
101
159
|
await new Promise((resolve, reject) => {
|
|
@@ -108,197 +166,63 @@ export async function startZeroHttpServer(opts) {
|
|
|
108
166
|
const address = server.address();
|
|
109
167
|
return {
|
|
110
168
|
url: `http://127.0.0.1:${address.port}`,
|
|
111
|
-
version:
|
|
112
|
-
rows: (table) => rowsForTable(
|
|
169
|
+
version: sync.watermark,
|
|
170
|
+
rows: (table) => rowsForTable(sqlite, table),
|
|
113
171
|
close: () => new Promise((resolve, reject) => {
|
|
114
|
-
server.close((
|
|
172
|
+
server.close((error) => {
|
|
173
|
+
sqlite.close();
|
|
174
|
+
error ? reject(error) : resolve();
|
|
175
|
+
});
|
|
115
176
|
}),
|
|
116
177
|
};
|
|
117
178
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
179
|
+
function initializeApplicationTables(sqlite, seed) {
|
|
180
|
+
sqlite.exec(`CREATE TABLE user_record (
|
|
181
|
+
user_id TEXT PRIMARY KEY,
|
|
182
|
+
display_name TEXT NOT NULL
|
|
183
|
+
)`);
|
|
184
|
+
sqlite.exec(`CREATE TABLE project_record (
|
|
185
|
+
project_id TEXT PRIMARY KEY,
|
|
186
|
+
owner_id TEXT NOT NULL,
|
|
187
|
+
project_name TEXT NOT NULL
|
|
188
|
+
)`);
|
|
189
|
+
sqlite.exec(`CREATE TABLE project_member (
|
|
190
|
+
member_id TEXT PRIMARY KEY,
|
|
191
|
+
project_id TEXT NOT NULL,
|
|
192
|
+
user_id TEXT NOT NULL
|
|
193
|
+
)`);
|
|
194
|
+
for (const table of Object.keys(tables)) {
|
|
195
|
+
const config = tables[table];
|
|
196
|
+
for (const row of seed?.[table] ?? []) {
|
|
197
|
+
const columns = Object.keys(row);
|
|
198
|
+
const physicalColumns = columns.map((column) => config.columns[column]);
|
|
199
|
+
sqlite
|
|
200
|
+
.prepare(`INSERT INTO "${config.physical}" (${physicalColumns
|
|
201
|
+
.map((column) => `"${column}"`)
|
|
202
|
+
.join(', ')}) VALUES (${columns.map(() => '?').join(', ')})`)
|
|
203
|
+
.run(...columns.map((column) => row[column]));
|
|
128
204
|
}
|
|
129
205
|
}
|
|
130
|
-
return tables;
|
|
131
206
|
}
|
|
132
|
-
function authenticate(req,
|
|
207
|
+
function authenticate(req, sqlite) {
|
|
133
208
|
const header = req.headers.authorization;
|
|
134
209
|
if (!header?.startsWith('Bearer token-'))
|
|
135
210
|
return null;
|
|
136
211
|
const userID = header.slice('Bearer token-'.length);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (owner)
|
|
142
|
-
return owner === userID;
|
|
143
|
-
clientGroupUsers.set(clientGroupID, userID);
|
|
144
|
-
return true;
|
|
212
|
+
const row = sqlite
|
|
213
|
+
.prepare('SELECT user_id FROM user_record WHERE user_id = ?')
|
|
214
|
+
.get(userID);
|
|
215
|
+
return row ? userID : null;
|
|
145
216
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
const rows = [];
|
|
149
|
-
const user = tables.user.get(userID);
|
|
150
|
-
if (user)
|
|
151
|
-
rows.push(wirePut('user', user));
|
|
152
|
-
for (const project of tables.project.values()) {
|
|
153
|
-
if (visibleProjectIDs.has(project.id)) {
|
|
154
|
-
rows.push(wirePut('project', project));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
for (const member of tables.member.values()) {
|
|
158
|
-
if (visibleProjectIDs.has(member.projectId)) {
|
|
159
|
-
rows.push(wirePut('member', member));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return rows;
|
|
163
|
-
}
|
|
164
|
-
function wirePut(table, row) {
|
|
165
|
-
const names = wireNames[table];
|
|
166
|
-
const value = {};
|
|
167
|
-
for (const [column, columnValue] of Object.entries(row)) {
|
|
168
|
-
const physicalColumn = names.columns[column];
|
|
169
|
-
if (!physicalColumn)
|
|
170
|
-
throw new Error(`missing wire mapping for ${table}.${column}`);
|
|
171
|
-
value[physicalColumn] = columnValue;
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
op: 'put',
|
|
175
|
-
tableName: names.table,
|
|
176
|
-
value,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function visibleProjectIDSet(tables, userID) {
|
|
180
|
-
const projectIDs = new Set();
|
|
181
|
-
for (const project of tables.project.values()) {
|
|
182
|
-
if (project.ownerId === userID)
|
|
183
|
-
projectIDs.add(project.id);
|
|
184
|
-
}
|
|
185
|
-
for (const member of tables.member.values()) {
|
|
186
|
-
if (member.userId === userID && tables.project.has(member.projectId)) {
|
|
187
|
-
projectIDs.add(member.projectId);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return projectIDs;
|
|
191
|
-
}
|
|
192
|
-
function findMutationGap(lmids, clientGroupID, mutations) {
|
|
193
|
-
const nextLMIDs = new Map();
|
|
194
|
-
for (const mutation of mutations) {
|
|
195
|
-
const current = nextLMIDs.get(mutation.clientID) ?? lmidFor(lmids, clientGroupID, mutation.clientID);
|
|
196
|
-
if (mutation.id <= current)
|
|
197
|
-
continue;
|
|
198
|
-
if (mutation.id !== current + 1) {
|
|
199
|
-
return `mutation id gap for ${mutation.clientID}: got ${mutation.id}, expected ${current + 1}`;
|
|
200
|
-
}
|
|
201
|
-
nextLMIDs.set(mutation.clientID, mutation.id);
|
|
202
|
-
}
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
function applyMutation(tables, userID, mutation) {
|
|
206
|
-
if (mutation.type !== 'custom')
|
|
207
|
-
return appError('unsupported');
|
|
208
|
-
const args = mutation.args[0] || {};
|
|
209
|
-
if (mutation.name === 'project|create') {
|
|
210
|
-
if (tables.project.has(args.id))
|
|
211
|
-
return appError('exists');
|
|
212
|
-
if (args.ownerId !== userID)
|
|
213
|
-
return appError('forbidden');
|
|
214
|
-
tables.project.set(args.id, {
|
|
215
|
-
id: args.id,
|
|
216
|
-
ownerId: args.ownerId,
|
|
217
|
-
name: args.name,
|
|
218
|
-
});
|
|
219
|
-
return {};
|
|
220
|
-
}
|
|
221
|
-
if (mutation.name === 'project|rename') {
|
|
222
|
-
const project = tables.project.get(args.id);
|
|
223
|
-
if (!project)
|
|
224
|
-
return appError('not-found');
|
|
225
|
-
if (project.ownerId !== userID)
|
|
226
|
-
return appError('forbidden');
|
|
227
|
-
tables.project.set(args.id, { ...project, name: args.name });
|
|
228
|
-
return {};
|
|
229
|
-
}
|
|
230
|
-
if (mutation.name === 'member|add') {
|
|
231
|
-
const project = tables.project.get(args.projectId);
|
|
232
|
-
if (!project)
|
|
233
|
-
return appError('not-found');
|
|
234
|
-
if (project.ownerId !== userID)
|
|
235
|
-
return appError('forbidden');
|
|
236
|
-
if (tables.member.has(args.id))
|
|
237
|
-
return appError('exists');
|
|
238
|
-
tables.member.set(args.id, {
|
|
239
|
-
id: args.id,
|
|
240
|
-
projectId: args.projectId,
|
|
241
|
-
userId: args.userId,
|
|
242
|
-
});
|
|
243
|
-
return {};
|
|
244
|
-
}
|
|
245
|
-
if (mutation.name === 'member|remove') {
|
|
246
|
-
const member = tables.member.get(args.id);
|
|
247
|
-
if (!member)
|
|
248
|
-
return appError('not-found');
|
|
249
|
-
const project = tables.project.get(member.projectId);
|
|
250
|
-
if (!project)
|
|
251
|
-
return appError('not-found');
|
|
252
|
-
if (project.ownerId !== userID)
|
|
253
|
-
return appError('forbidden');
|
|
254
|
-
tables.member.delete(args.id);
|
|
255
|
-
return {};
|
|
256
|
-
}
|
|
257
|
-
return appError('unsupported');
|
|
258
|
-
}
|
|
259
|
-
function appError(details) {
|
|
260
|
-
return { error: 'app', details };
|
|
261
|
-
}
|
|
262
|
-
function lastMutationIDChanges(lmids, clientGroupID) {
|
|
263
|
-
return Object.fromEntries(lmids.get(clientGroupID) || []);
|
|
264
|
-
}
|
|
265
|
-
function lmidFor(lmids, clientGroupID, clientID) {
|
|
266
|
-
return lmids.get(clientGroupID)?.get(clientID) || 0;
|
|
267
|
-
}
|
|
268
|
-
function setLMID(lmids, clientGroupID, clientID, id) {
|
|
269
|
-
let group = lmids.get(clientGroupID);
|
|
270
|
-
if (!group) {
|
|
271
|
-
group = new Map();
|
|
272
|
-
lmids.set(clientGroupID, group);
|
|
273
|
-
}
|
|
274
|
-
group.set(clientID, id);
|
|
275
|
-
}
|
|
276
|
-
function resultForMutation(results, clientGroupID, clientID, id) {
|
|
277
|
-
return results.get(clientGroupID)?.get(clientID)?.get(id);
|
|
278
|
-
}
|
|
279
|
-
function setMutationResult(results, clientGroupID, clientID, id, result) {
|
|
280
|
-
let group = results.get(clientGroupID);
|
|
281
|
-
if (!group) {
|
|
282
|
-
group = new Map();
|
|
283
|
-
results.set(clientGroupID, group);
|
|
284
|
-
}
|
|
285
|
-
let client = group.get(clientID);
|
|
286
|
-
if (!client) {
|
|
287
|
-
client = new Map();
|
|
288
|
-
group.set(clientID, client);
|
|
289
|
-
}
|
|
290
|
-
client.set(id, result);
|
|
291
|
-
}
|
|
292
|
-
function rowsForTable(tables, table) {
|
|
293
|
-
if (!isTableName(table))
|
|
217
|
+
function rowsForTable(sqlite, table) {
|
|
218
|
+
if (!(table in tables))
|
|
294
219
|
return [];
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return { ...row };
|
|
220
|
+
const config = tables[table];
|
|
221
|
+
const logicalColumns = Object.entries(config.columns);
|
|
222
|
+
return sqlite
|
|
223
|
+
.prepare(`SELECT * FROM "${config.physical}"`)
|
|
224
|
+
.all()
|
|
225
|
+
.map((row) => Object.fromEntries(logicalColumns.map(([logical, physical]) => [logical, String(row[physical])])));
|
|
302
226
|
}
|
|
303
227
|
async function readJSON(req) {
|
|
304
228
|
let body = '';
|