@opendatalabs/personal-server-ts-server 1.8.0 → 1.10.0
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/api-auth.d.ts.map +1 -1
- package/dist/api-auth.js +1 -0
- package/dist/api-auth.js.map +1 -1
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +30 -3
- package/dist/app.js.map +1 -1
- package/dist/bootstrap.d.ts +8 -0
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +60 -0
- package/dist/bootstrap.js.map +1 -1
- package/dist/routes/data.d.ts +6 -0
- package/dist/routes/data.d.ts.map +1 -1
- package/dist/routes/data.js +1 -0
- package/dist/routes/data.js.map +1 -1
- package/dist/routes/derivatives.d.ts +33 -0
- package/dist/routes/derivatives.d.ts.map +1 -0
- package/dist/routes/derivatives.js +33 -0
- package/dist/routes/derivatives.js.map +1 -0
- package/dist/storage/question-store.d.ts +9 -0
- package/dist/storage/question-store.d.ts.map +1 -0
- package/dist/storage/question-store.js +114 -0
- package/dist/storage/question-store.js.map +1 -0
- package/dist/ui/ps-lite-debug.js +2000 -96
- package/package.json +3 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite-backed store for derivative question registrations. Lives in the
|
|
3
|
+
* same index.db as the data index; its own table, created on first use
|
|
4
|
+
* (CREATE TABLE IF NOT EXISTS), so no index schema version bump.
|
|
5
|
+
*/
|
|
6
|
+
import { matchesQuestionFilter, } from "@opendatalabs/personal-server-ts-core/derivatives";
|
|
7
|
+
const CREATE_TABLE_SQL = `
|
|
8
|
+
CREATE TABLE IF NOT EXISTS derivative_questions (
|
|
9
|
+
question_id TEXT PRIMARY KEY,
|
|
10
|
+
derived_scope TEXT NOT NULL,
|
|
11
|
+
source_scopes TEXT NOT NULL,
|
|
12
|
+
question TEXT NOT NULL,
|
|
13
|
+
model TEXT,
|
|
14
|
+
registered_by TEXT NOT NULL,
|
|
15
|
+
status TEXT NOT NULL,
|
|
16
|
+
error TEXT,
|
|
17
|
+
created_at TEXT NOT NULL,
|
|
18
|
+
updated_at TEXT NOT NULL,
|
|
19
|
+
last_computed_at TEXT,
|
|
20
|
+
derived_version INTEGER,
|
|
21
|
+
derived_collected_at TEXT
|
|
22
|
+
)`;
|
|
23
|
+
const CREATE_INDEX_SQL = "CREATE INDEX IF NOT EXISTS idx_derivative_questions_derived_scope ON derivative_questions (derived_scope)";
|
|
24
|
+
function toRegistration(row) {
|
|
25
|
+
return {
|
|
26
|
+
questionId: row.question_id,
|
|
27
|
+
derivedScope: row.derived_scope,
|
|
28
|
+
sourceScopes: JSON.parse(row.source_scopes),
|
|
29
|
+
question: row.question,
|
|
30
|
+
model: row.model,
|
|
31
|
+
registeredBy: JSON.parse(row.registered_by),
|
|
32
|
+
status: row.status,
|
|
33
|
+
error: row.error,
|
|
34
|
+
createdAt: row.created_at,
|
|
35
|
+
updatedAt: row.updated_at,
|
|
36
|
+
lastComputedAt: row.last_computed_at,
|
|
37
|
+
derivedVersion: row.derived_version,
|
|
38
|
+
derivedCollectedAt: row.derived_collected_at,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function createSqliteQuestionStore(db) {
|
|
42
|
+
db.exec(CREATE_TABLE_SQL);
|
|
43
|
+
db.exec(CREATE_INDEX_SQL);
|
|
44
|
+
const listAll = db.prepare("SELECT * FROM derivative_questions ORDER BY created_at ASC, question_id ASC");
|
|
45
|
+
const getOne = db.prepare("SELECT * FROM derivative_questions WHERE question_id = ?");
|
|
46
|
+
const insertOne = db.prepare(`
|
|
47
|
+
INSERT INTO derivative_questions (
|
|
48
|
+
question_id, derived_scope, source_scopes, question, model,
|
|
49
|
+
registered_by, status, error, created_at, updated_at,
|
|
50
|
+
last_computed_at, derived_version, derived_collected_at
|
|
51
|
+
) VALUES (
|
|
52
|
+
@question_id, @derived_scope, @source_scopes, @question, @model,
|
|
53
|
+
@registered_by, @status, @error, @created_at, @updated_at,
|
|
54
|
+
@last_computed_at, @derived_version, @derived_collected_at
|
|
55
|
+
)`);
|
|
56
|
+
const updateOne = db.prepare(`
|
|
57
|
+
UPDATE derivative_questions SET
|
|
58
|
+
status = @status,
|
|
59
|
+
error = @error,
|
|
60
|
+
updated_at = @updated_at,
|
|
61
|
+
last_computed_at = @last_computed_at,
|
|
62
|
+
derived_version = @derived_version,
|
|
63
|
+
derived_collected_at = @derived_collected_at
|
|
64
|
+
WHERE question_id = @question_id`);
|
|
65
|
+
const deleteOne = db.prepare("DELETE FROM derivative_questions WHERE question_id = ?");
|
|
66
|
+
return {
|
|
67
|
+
async list(filter) {
|
|
68
|
+
return listAll.all()
|
|
69
|
+
.map(toRegistration)
|
|
70
|
+
.filter((registration) => matchesQuestionFilter(registration, filter));
|
|
71
|
+
},
|
|
72
|
+
async get(questionId) {
|
|
73
|
+
const row = getOne.get(questionId);
|
|
74
|
+
return row ? toRegistration(row) : null;
|
|
75
|
+
},
|
|
76
|
+
async insert(registration) {
|
|
77
|
+
insertOne.run({
|
|
78
|
+
question_id: registration.questionId,
|
|
79
|
+
derived_scope: registration.derivedScope,
|
|
80
|
+
source_scopes: JSON.stringify(registration.sourceScopes),
|
|
81
|
+
question: registration.question,
|
|
82
|
+
model: registration.model,
|
|
83
|
+
registered_by: JSON.stringify(registration.registeredBy),
|
|
84
|
+
status: registration.status,
|
|
85
|
+
error: registration.error,
|
|
86
|
+
created_at: registration.createdAt,
|
|
87
|
+
updated_at: registration.updatedAt,
|
|
88
|
+
last_computed_at: registration.lastComputedAt,
|
|
89
|
+
derived_version: registration.derivedVersion,
|
|
90
|
+
derived_collected_at: registration.derivedCollectedAt,
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
async update(questionId, patch) {
|
|
94
|
+
const current = getOne.get(questionId);
|
|
95
|
+
if (!current)
|
|
96
|
+
return null;
|
|
97
|
+
const merged = { ...toRegistration(current), ...patch };
|
|
98
|
+
updateOne.run({
|
|
99
|
+
question_id: questionId,
|
|
100
|
+
status: merged.status,
|
|
101
|
+
error: merged.error,
|
|
102
|
+
updated_at: merged.updatedAt,
|
|
103
|
+
last_computed_at: merged.lastComputedAt,
|
|
104
|
+
derived_version: merged.derivedVersion,
|
|
105
|
+
derived_collected_at: merged.derivedCollectedAt,
|
|
106
|
+
});
|
|
107
|
+
return merged;
|
|
108
|
+
},
|
|
109
|
+
async delete(questionId) {
|
|
110
|
+
return deleteOne.run(questionId).changes > 0;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=question-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question-store.js","sourceRoot":"","sources":["../../src/storage/question-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,qBAAqB,GAItB,MAAM,mDAAmD,CAAC;AAE3D,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;EAevB,CAAC;AAEH,MAAM,gBAAgB,GACpB,2GAA2G,CAAC;AAkB9G,SAAS,cAAc,CAAC,GAAQ;IAC9B,OAAO;QACL,UAAU,EAAE,GAAG,CAAC,WAAW;QAC3B,YAAY,EAAE,GAAG,CAAC,aAAa;QAC/B,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAa;QACvD,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAyB;QACnE,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,cAAc,EAAE,GAAG,CAAC,gBAAgB;QACpC,cAAc,EAAE,GAAG,CAAC,eAAe;QACnC,kBAAkB,EAAE,GAAG,CAAC,oBAAo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