From 132c9100c15c834485f1d04c6db452e9f00362d6 Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Fri, 27 Nov 2026 23:10:36 +0000 Subject: [PATCH 1/5] Move to OSL 24: osl fix rewrites, def type, websocket globals before startup --- main.osl | 5 ++-- src/auth/auth.osl | 4 +-- src/auth/privacy-policy.test.osl | 2 +- src/auth/user-identity.osl | 2 +- src/classroom/classroom-billing-policy.osl | 2 +- src/classroom/classroom-legal.osl | 4 +-- src/classroom/classroom-policy.osl | 6 ++-- src/classroom/classroom-release.osl | 2 +- src/classroom/classroom-schools.osl | 10 +++---- src/community/comments.osl | 4 +-- src/git/pulls.osl | 4 +-- src/history/history-delta.test.osl | 10 +++---- src/history/history-migration.test.osl | 4 +-- src/projects/extensions.test.osl | 2 +- src/projects/play-signals.osl | 32 +++++++++++----------- src/projects/play-signals.test.osl | 2 +- src/projects/project-discovery.osl | 2 +- src/projects/project-lock.osl | 2 +- src/projects/project-remix.osl | 6 ++-- src/projects/project-response.osl | 2 +- src/projects/project-upload-publish.osl | 2 +- src/projects/related-projects.osl | 2 +- src/projects/upload-parts.test.osl | 2 +- src/rotur/rotur-badges.test.osl | 2 +- src/storage/archive-security.test.osl | 2 +- src/storage/asset-routing.osl | 2 +- src/storage/backpack-policy.test.osl | 2 +- src/storage/backpack.osl | 4 +-- src/storage/r2-snapshot-serving.test.osl | 2 +- src/storage/r2-upload-queue.osl | 2 +- src/storage/r2-upload-queue.test.osl | 2 +- src/storage/r2.osl | 10 +++---- src/storage/storage-ledger.test.osl | 2 +- src/storage/storage.osl | 8 +++--- 34 files changed, 76 insertions(+), 75 deletions(-) diff --git a/main.osl b/main.osl index 9229350..6e29aa8 100644 --- a/main.osl +++ b/main.osl @@ -36,6 +36,9 @@ import "./src/community" import "./src/admin" import "./src/classroom" +*ws.Server gameRealtimeSocket = ws.New() +*ws.Server siteRealtimeSocket = ws.New() + ensureDirectories() string thumbnailSecret = loadThumbnailSecret(thumbnailSecretFile) void initCommunityDatabase() catch (err) ( @@ -120,8 +123,6 @@ thread.new(developmentFeedLoop) thread.new(vanityLapseLoop) *serve.Router app = serve.new() -*ws.Server gameRealtimeSocket = ws.New() -*ws.Server siteRealtimeSocket = ws.New() app.bodyLimit(maxAppRequestBytes) app.use(realtimeUpgradeGuard) diff --git a/src/auth/auth.osl b/src/auth/auth.osl index 8bdf3b1..572d75c 100644 --- a/src/auth/auth.osl +++ b/src/auth/auth.osl @@ -90,7 +90,7 @@ def deleteSession(string token) boolean ( return false ) sessionCache.delete(token) - return fs.remove(sessionsDir ++ token ++ ".json") + return fs.remove(sessionsDir ++ token ++ ".json").isOk() ) def cleanupExpiredSessions() ( @@ -318,7 +318,7 @@ def externalDependency(string url) object ( def handleDependencyHealth(*serve.Context c) ( string probePath = tmpDir ++ "health-" ++ randomString(8) - boolean storageOk = fs.writeFile(probePath, "ok") + boolean storageOk = fs.writeFile(probePath, "ok").isOk() if storageOk ( storageOk = fs.readFile(probePath).unwrapOr("") == "ok" void fs.remove(probePath) diff --git a/src/auth/privacy-policy.test.osl b/src/auth/privacy-policy.test.osl index db2dbec..7310795 100644 --- a/src/auth/privacy-policy.test.osl +++ b/src/auth/privacy-policy.test.osl @@ -45,7 +45,7 @@ testing.assert(privacyAdult.minor == false, "adult activity privacy is not a min testing.assert(privacyAdult.hiddenLibrary.assert(array).contains("p9"), "hidden library items are carried over") object privacyMinor = activityPrivacy({username: "sam", minor: true}) testing.assert(privacyMinor.showActivity == false, "minor activity privacy hides activity by default") -testing.assert(privacyMinor.hiddenLibrary.assert(array).len == 0, "a missing hidden list is empty") +testing.assert(privacyMinor.hiddenLibrary.len == 0, "a missing hidden list is empty") object visibilities = {p1: "public", p2: "unlisted", p3: "private", p9: "public"} object openPrivacy = {showActivity: true, minor: false, hiddenLibrary: ["p9"]} diff --git a/src/auth/user-identity.osl b/src/auth/user-identity.osl index 5210f47..9668d2c 100644 --- a/src/auth/user-identity.osl +++ b/src/auth/user-identity.osl @@ -885,7 +885,7 @@ def reconcileDeletedUsers() ( ) ) ) - ids = ids.filter((any id) boolean -> !isStudentUserId(id.toStr())) + ids = ids.filter(def(any id) boolean -> !isStudentUserId(id.toStr())) if ids.len == 0 ( return ) diff --git a/src/classroom/classroom-billing-policy.osl b/src/classroom/classroom-billing-policy.osl index a4f989e..1e469d9 100644 --- a/src/classroom/classroom-billing-policy.osl +++ b/src/classroom/classroom-billing-policy.osl @@ -29,7 +29,7 @@ def stripeSignatureValid(string header, string payload, string secret, number no return false ) string expected = crypto.hmac("sha256", secret, signedAt.toInt().toStr() ++ "." ++ payload) - array signatures = parts.v1.assert(array) + array signatures = parts.v1 for i signatures.len ( if crypto.constantTimeCompare(expected, signatures[i].toStr()) ( return true diff --git a/src/classroom/classroom-legal.osl b/src/classroom/classroom-legal.osl index 86a588f..b423c3d 100644 --- a/src/classroom/classroom-legal.osl +++ b/src/classroom/classroom-legal.osl @@ -87,7 +87,7 @@ def studentExportRow(object student) object ( lastLoginAt: student.lastLoginAt ?? 0, failedLogins: student.failedLogins ?? 0, lockedUntil: student.lockedUntil ?? 0, - projects: ownerIndexEntries(student.username.toStr(), true).map((any entry) any -> {id: entry.id, title: entry.title, created: entry.created ?? 0, edited: entry.edited}) + projects: ownerIndexEntries(student.username.toStr(), true).map(def(any entry) any -> {id: entry.id, title: entry.title, created: entry.created ?? 0, edited: entry.edited}) } ) @@ -158,7 +158,7 @@ def handleExportClassStudent(*serve.Context c) ( submissions: submissionDocs.where("studentId", "==", studentId).all(), groups: groups, activity: activity, - pendingRelease: classroomClaimDocs.where("studentId", "==", studentId).all().map((any claim) any -> {createdAt: claim.createdAt, expiresAt: claim.expiresAt}) + pendingRelease: classroomClaimDocs.where("studentId", "==", studentId).all().map(def(any claim) any -> {createdAt: claim.createdAt, expiresAt: claim.expiresAt}) }) ) diff --git a/src/classroom/classroom-policy.osl b/src/classroom/classroom-policy.osl index 6eff500..a7d1493 100644 --- a/src/classroom/classroom-policy.osl +++ b/src/classroom/classroom-policy.osl @@ -294,7 +294,7 @@ def classAfterTeacherErased(object classDoc, string userId) object ( object successor = kept[1].assertElse(object, {}) next.ownerId = (successor.userId ?? "").toStr() next.owner = (successor.username ?? "").toStr() - kept = kept.filter((any teacher) boolean -> (teacher.assertElse(object, {}).userId ?? "").toStr() != next.ownerId) + kept = kept.filter(def(any teacher) boolean -> (teacher.assertElse(object, {}).userId ?? "").toStr() != next.ownerId) ) next.coTeachers = kept return next @@ -302,8 +302,8 @@ def classAfterTeacherErased(object classDoc, string userId) object ( def schoolAfterTeacherErased(object school, string userId) object ( object next = school.clone() - array teachers = (school.teacherIds ?? []).assertElse(array, []).filter((any id) boolean -> id.toStr() != userId) - array admins = (school.adminIds ?? []).assertElse(array, []).filter((any id) boolean -> id.toStr() != userId) + array teachers = (school.teacherIds ?? []).assertElse(array, []).filter(def(any id) boolean -> id.toStr() != userId) + array admins = (school.adminIds ?? []).assertElse(array, []).filter(def(any id) boolean -> id.toStr() != userId) if admins.len == 0 and teachers.len > 0 ( admins.append(teachers[1].toStr()) ) diff --git a/src/classroom/classroom-release.osl b/src/classroom/classroom-release.osl index 1226fde..122f60c 100644 --- a/src/classroom/classroom-release.osl +++ b/src/classroom/classroom-release.osl @@ -173,7 +173,7 @@ def leaveClassGroups(object student) ( object group = groups[i].assert(object) array ids = group.studentIds.assertElse(array, []) if ids.contains(studentId) ( - group.studentIds = ids.filter((any id) boolean -> id.toStr() != studentId) + group.studentIds = ids.filter(def(any id) boolean -> id.toStr() != studentId) putDocument(classroomGroupDocs, group["_id"].toStr(), group) ) ) diff --git a/src/classroom/classroom-schools.osl b/src/classroom/classroom-schools.osl index 0557584..6650022 100644 --- a/src/classroom/classroom-schools.osl +++ b/src/classroom/classroom-schools.osl @@ -151,8 +151,8 @@ def handleRemoveSchoolTeacher(*serve.Context c) ( c.badRequest("a school needs at least one admin") return ) - school.teacherIds = (school.teacherIds ?? []).assertElse(array, []).filter((any id) boolean -> id.toStr() != teacherId) - school.adminIds = admins.filter((any id) boolean -> id.toStr() != teacherId) + school.teacherIds = (school.teacherIds ?? []).assertElse(array, []).filter(def(any id) boolean -> id.toStr() != teacherId) + school.adminIds = admins.filter(def(any id) boolean -> id.toStr() != teacherId) putDocument(schoolDocs, school["_id"].toStr(), school) invalidateClassroomPool(teacherId) classroomPoolCache.delete(school["_id"].toStr()) @@ -180,7 +180,7 @@ def handleSetSchoolAdmin(*serve.Context c) ( c.badRequest("a school needs at least one admin") return ) - admins = admins.filter((any id) boolean -> id.toStr() != teacherId) + admins = admins.filter(def(any id) boolean -> id.toStr() != teacherId) array teachers = (school.teacherIds ?? []).assertElse(array, []) if !teachers.contains(teacherId) ( teachers.append(teacherId) @@ -239,7 +239,7 @@ def handleExportSchool(*serve.Context c) ( disabled: student.disabled == true, createdAt: student.createdAt, lastLoginAt: student.lastLoginAt ?? 0, - projects: ownerIndexEntries(student.username.toStr(), true).map((any entry) any -> {id: entry.id, title: entry.title, edited: entry.edited}) + projects: ownerIndexEntries(student.username.toStr(), true).map(def(any entry) any -> {id: entry.id, title: entry.title, edited: entry.edited}) }) ) classes.append({ @@ -264,7 +264,7 @@ def handleAdminListSchools(*serve.Context c) ( for i schools.len ( object school = schools[i].assert(object) string key = school["_id"].toStr() - rows.append({id: key, name: school.name, admins: (school.adminIds ?? []).assertElse(array, []).map((any id) any -> usernameForId(id.toStr())), plan: effectiveClassroomPlan((classroomPlanDocs.findById(key) ?? {}), timestamp)}) + rows.append({id: key, name: school.name, admins: (school.adminIds ?? []).assertElse(array, []).map(def(any id) any -> usernameForId(id.toStr())), plan: effectiveClassroomPlan((classroomPlanDocs.findById(key) ?? {}), timestamp)}) ) c.json(200, {ok: true, schools: rows}) ) diff --git a/src/community/comments.osl b/src/community/comments.osl index 1a18f25..acd9a1b 100644 --- a/src/community/comments.osl +++ b/src/community/comments.osl @@ -356,8 +356,8 @@ def commentPage(array allComments,*serve.Context c) object ( string issueFilter = (c.query("issue") ?? "") if validIssueFilter(issueFilter) ( object threads = issueThreads(comments, roots, issueFilter, c.queryInt("number", 0)) - comments = threads.comments.assert(array) - roots = threads.roots.assert(array) + comments = threads.comments + roots = threads.roots ) if (c.query("sort") ?? "") == "donations" ( for i roots.len ( diff --git a/src/git/pulls.osl b/src/git/pulls.osl index 505e796..f906d7e 100644 --- a/src/git/pulls.osl +++ b/src/git/pulls.osl @@ -597,8 +597,8 @@ def handleGetPullTimeline(*serve.Context c) ( array sourceCommits = [] array targetCommits = [] if canInspectPullWithSource(pull, target, source, c) ( - array targetHistory = projectVersionHistory(target).commits.assert(array) - sourceCommits = commitsAfter(projectVersionHistory(source).commits.assert(array), pull.baseCommit.toStr(), pull.created.toNum()) + array targetHistory = projectVersionHistory(target).commits + sourceCommits = commitsAfter(projectVersionHistory(source).commits, pull.baseCommit.toStr(), pull.created.toNum()) sourceCommits = commitsNotIn(sourceCommits, targetHistory) targetCommits = commitsAfter(targetHistory, pull.targetHead.toStr(), pull.created.toNum()) ) diff --git a/src/history/history-delta.test.osl b/src/history/history-delta.test.osl index 4d0a4f1..7a0bdea 100644 --- a/src/history/history-delta.test.osl +++ b/src/history/history-delta.test.osl @@ -49,17 +49,17 @@ object delta = { } object merged = mergeDeltaHistory(project, delta, base) -array commits = merged.commits.assert(array) +array commits = merged.commits testing.assert(commits.len == 4, "delta and inherited commits are combined") testing.assert(commits[1].sha == second and commits[2].sha == first, "new commits stay newest first") testing.assert(commits[3].sha == base and commits[3].message == "Base", "the inherited base metadata wins") testing.assert(commits[4].sha == older, "history before the base is preserved") -array nodes = merged.graph.assert(object).nodes.assert(array) +array nodes = merged.graph.nodes testing.assert(nodes.len == 4, "graph nodes are deduplicated") testing.assert(nodes[3].message == "Base", "the incoming base node does not replace inherited metadata") -array mainLog = graphBranchLog(merged.graph.assert(object), "main") +array mainLog = graphBranchLog(merged.graph, "main") testing.assert(mainLog.len == 4, "branch log is stitched without duplicates") testing.assert(mainLog[1] == second and mainLog[2] == first and mainLog[3] == base and mainLog[4] == older, "branch log spans delta and base") array releaseLog = graphBranchLog(merged.graph.assert(object), "release") @@ -91,8 +91,8 @@ object mergeDelta = { } } object pullMerged = mergeDeltaHistory(sourceHistory, mergeDelta, base) -array pullMergedCommits = pullMerged.commits.assert(array) +array pullMergedCommits = pullMerged.commits testing.assert(pullMergedCommits.len == 3, "an explicit PR merge keeps the source commits") testing.assert(pullMergedCommits[1].sha == mergeHead and pullMergedCommits[2].sha == pullHead and pullMergedCommits[3].sha == base, "the PR merge is prepended to source history") -array pullMergedLog = graphBranchLog(pullMerged.graph.assert(object), "main") +array pullMergedLog = graphBranchLog(pullMerged.graph, "main") testing.assert(pullMergedLog.len == 3 and pullMergedLog[1] == mergeHead and pullMergedLog[2] == pullHead and pullMergedLog[3] == base, "the main log connects the merge commit to the accepted source history") diff --git a/src/history/history-migration.test.osl b/src/history/history-migration.test.osl index 2773111..e4ad5bc 100644 --- a/src/history/history-migration.test.osl +++ b/src/history/history-migration.test.osl @@ -51,7 +51,7 @@ def projectGitHead(object project) string ( def copyStoredProjectJsonToPath(object project, string outputPath) boolean ( string plain = outputPath ++ ".json" void fs.writeFile(plain, "{\"targets\":[]}") - boolean ok = zip.gzip(plain, outputPath, {maxInputBytes: 1024, maxBytes: 1024}) + boolean ok = zip.gzip(plain, outputPath, {maxInputBytes: 1024, maxBytes: 1024}).isOk() void fs.remove(plain) return ok ) @@ -95,7 +95,7 @@ def projectWorkspaceSnapshotKey(string hash) string ( ) def stageR2Blob(string key, byte[] data, string contentType, string encoding) boolean ( - return fs.writeFileBytes(tmpDir ++ key, data) + return fs.writeFileBytes(tmpDir ++ key, data).isOk() ) def removeProjectStorageKeyIfOrphaned(string key, string id, boolean workspace) ( diff --git a/src/projects/extensions.test.osl b/src/projects/extensions.test.osl index 0424d01..674db74 100644 --- a/src/projects/extensions.test.osl +++ b/src/projects/extensions.test.osl @@ -29,7 +29,7 @@ def readFile(string path) object ( return {ok: true, data: parsed.unwrap()} ) def writeFile(string path, object data) boolean ( - return fs.writeFile(path, json.stringify(data)) + return (fs.writeFile(path, json.stringify(data))).isOk() ) def randomString(number length) string ( return "r" * length diff --git a/src/projects/play-signals.osl b/src/projects/play-signals.osl index 0b749a2..53b4f30 100644 --- a/src/projects/play-signals.osl +++ b/src/projects/play-signals.osl @@ -31,11 +31,11 @@ def playerKeyOf(string userId, string username) string ( ) def addHeldPlay(PlaySignals signals, string projectId, string player) ( - signals.held[projectId] = (signals.held[projectId] ?? 0) + 1 - string[] byProject = signals.heldBy[projectId] ?? [] + signals.held[projectId] = signals.held[projectId] + 1 + string[] byProject = signals.heldBy[projectId] byProject.append(player) signals.heldBy[projectId] = byProject - string[] byPlayer = signals.heldProjects[player] ?? [] + string[] byPlayer = signals.heldProjects[player] byPlayer.append(projectId) signals.heldProjects[player] = byPlayer ) @@ -47,11 +47,11 @@ def playSignalsFrom(object[] rows, string[string] ownerKeys, number now) PlaySig string projectId = (row.projectId ?? "").toStr() string username = (row.username ?? "").toStr() string player = playerKeyOf((row.userId ?? "").toStr(), username) - string owner = ownerKeys[projectId] ?? "" + string owner = ownerKeys[projectId] boolean ownPlay = owner != "" and username.toLower().strip() == owner boolean recent = now - (row.updated ?? 0).toNum() <= playWindowMs if projectId != "" and player != "" and !ownPlay and recent ( - signals.players[projectId] = (signals.players[projectId] ?? 0) + 1 + signals.players[projectId] = signals.players[projectId] + 1 if (row.duration ?? 0).toNum() >= heldPlayMs ( addHeldPlay(signals, projectId, player) ) @@ -61,8 +61,8 @@ def playSignalsFrom(object[] rows, string[string] ownerKeys, number now) PlaySig ) def holdWeight(PlaySignals signals, string projectId) number ( - number playerCount = signals.players[projectId] ?? 0 - number heldCount = signals.held[projectId] ?? 0 + number playerCount = signals.players[projectId] + number heldCount = signals.held[projectId] return (heldCount + 2) / (playerCount + 4) ) @@ -102,17 +102,17 @@ def compareRankedIds(RankedId a, RankedId b) int ( ) def coPlayScores(PlaySignals signals, string projectId) object ( - string[] sharedPlayers = signals.heldBy[projectId] ?? [] + string[] sharedPlayers = signals.heldBy[projectId] string[number] scores = {} string[number] counts = {} for i sharedPlayers.len ( - string[] playedNext = signals.heldProjects[sharedPlayers[i]] ?? [] + string[] playedNext = signals.heldProjects[sharedPlayers[i]] number share = 1 / (playedNext.len.toNum().sqrt() ?? 1) for j playedNext.len ( string otherId = playedNext[j] if otherId != projectId ( - scores[otherId] = (scores[otherId] ?? 0) + share - counts[otherId] = (counts[otherId] ?? 0) + 1 + scores[otherId] = scores[otherId] + share + counts[otherId] = counts[otherId] + 1 ) ) ) @@ -121,16 +121,16 @@ def coPlayScores(PlaySignals signals, string projectId) object ( def coPlayedIds(PlaySignals signals, string projectId, number limit) string[] ( string[] ids = [] - if (signals.held[projectId] ?? 0) < minHeldPlayers ( + if signals.held[projectId] < minHeldPlayers ( return ids ) object found = coPlayScores(signals, projectId) - string[number] scores = found.scores.assert(string[number]) - string[number] counts = found.counts.assert(string[number]) + string[number] scores = found.scores + string[number] counts = found.counts RankedId[] ranked = [] for otherId of scores ( - if (counts[otherId] ?? 0) >= minCoPlayers ( - ranked.append(RankedId(otherId, scores[otherId] ?? 0)) + if counts[otherId] >= minCoPlayers ( + ranked.append(RankedId(otherId, scores[otherId])) ) ) RankedId[] sorted = ranked.sort(compareRankedIds) diff --git a/src/projects/play-signals.test.osl b/src/projects/play-signals.test.osl index 56f2610..85a63cf 100644 --- a/src/projects/play-signals.test.osl +++ b/src/projects/play-signals.test.osl @@ -48,7 +48,7 @@ testing.assert(holdWeight(signals, "unplayed") == 0.5, "projects nobody has play testing.assert(ids(coPlayedIds(signals, "bait", 5)) == "pair", "a project needs three shared players to count as co-played") testing.assert(ids(coPlayedIds(signals, "thin", 5)) == "", "projects with few held players get no co-plays") testing.assert(ids(coPlayedIds(signals, "solo", 5)) == "", "the owner's own plays never link projects") -testing.assert((signals.players["pair"] ?? 0) == 4, "legacy rows without a user id count once under their username") +testing.assert(signals.players["pair"] == 4, "legacy rows without a user id count once under their username") object[] tied = [] for i 30 ( diff --git a/src/projects/project-discovery.osl b/src/projects/project-discovery.osl index 8a0566e..b4e7195 100644 --- a/src/projects/project-discovery.osl +++ b/src/projects/project-discovery.osl @@ -34,7 +34,7 @@ def sharedPlayRows(array rows) object[] ( if key != "" and !allowed.contains(key) ( allowed[key] = playerUnbanned(username, (row.userId ?? "").toStr()) and effectiveShowRecentActivity(loadProfile(username)) ) - if key != "" and (allowed[key] ?? false) ( + if key != "" and allowed[key] ( kept.append(row) ) ) diff --git a/src/projects/project-lock.osl b/src/projects/project-lock.osl index b470097..7976fe0 100644 --- a/src/projects/project-lock.osl +++ b/src/projects/project-lock.osl @@ -4,7 +4,7 @@ def projectSaveLock(string id) string ( return "project-history-" ++ id ) -def runLocked(string lockName, function work) ( +def runLocked(string lockName, def work) ( sync.lock(lockName) defer sync.unlock(lockName) work() diff --git a/src/projects/project-remix.osl b/src/projects/project-remix.osl index 9f88900..11650a8 100644 --- a/src/projects/project-remix.osl +++ b/src/projects/project-remix.osl @@ -309,12 +309,12 @@ def prepareFork(object source, ForkRequest request, UpdateLookups lookups) Prepa if !jsonSnapshot.ok ( return forkRefused(500, "copy_failed", "could not copy the original project, try again") ) - parent = jsonSnapshot.project.assert(object) + parent = jsonSnapshot.project object workspaceSnapshots = ensureProjectWorkspaceSnapshots(parent) if !workspaceSnapshots.ok ( return forkRefused(500, "history_failed", "could not prepare the original project history, try again") ) - parent = workspaceSnapshots.project.assert(object) + parent = workspaceSnapshots.project if !projectHasWorkspace(parent) ( return forkRefused(409, "history_unavailable", "prepare the original project's history before remixing") @@ -324,7 +324,7 @@ def prepareFork(object source, ForkRequest request, UpdateLookups lookups) Prepa if archived.ok != true ( return forkRefused(409, "history_unavailable", "requested branch history is unavailable") ) - object forkHistory = archived.manifest.assert(object) + object forkHistory = archived.manifest byte[] forkBody = fs.readFileBytes(forkPath).unwrapOr("".toBytes()) void fs.remove(forkPath) PreparedFork prepared = PreparedFork{parent: parent, history: forkBody, manifest: forkHistory, hold: noStorageHold()} diff --git a/src/projects/project-response.osl b/src/projects/project-response.osl index 7f8d7df..ba3af7d 100644 --- a/src/projects/project-response.osl +++ b/src/projects/project-response.osl @@ -266,7 +266,7 @@ def projectResponse(object project,*serve.Context c) object ( if project.contains("gitBranch") and project.gitBranch != null and project.gitBranch.toStr() != "" ( response.gitBranch = project.gitBranch ) - response.commitCount = projectVersionHistory(project).commits.assert(array).len + response.commitCount = projectVersionHistory(project).commits.len response.remixBaseCommit = "" if project.contains("remixBaseCommit") and project.remixBaseCommit != null ( response.remixBaseCommit = project.remixBaseCommit diff --git a/src/projects/project-upload-publish.osl b/src/projects/project-upload-publish.osl index 14d8a7a..20dd534 100644 --- a/src/projects/project-upload-publish.osl +++ b/src/projects/project-upload-publish.osl @@ -115,7 +115,7 @@ def projectWithUploadHistory(object project) object ( log "WARNING: project " ++ project.id.toStr() ++ " uploaded without history and fallback generation failed: " ++ generatedHistory.error.toStr() return project ) - return generatedHistory.project.assert(object) + return generatedHistory.project ) def completeUploadPull(object project, UploadRequest request, boolean canMerge) Refusal ( diff --git a/src/projects/related-projects.osl b/src/projects/related-projects.osl index f632db1..668a810 100644 --- a/src/projects/related-projects.osl +++ b/src/projects/related-projects.osl @@ -57,7 +57,7 @@ def relatedProjectEntries(object[] entries, string id, string[] excluded, string number coPlayLimit = ownerLimit for i coPlayed.len ( if pick.related.len < coPlayLimit and byId.contains(coPlayed[i]) ( - void pickRelated(pick, byId[coPlayed[i]].assert(object)) + void pickRelated(pick, byId[coPlayed[i]]) ) ) number ownerCount = 0 diff --git a/src/projects/upload-parts.test.osl b/src/projects/upload-parts.test.osl index 95e1f5e..d3f9719 100644 --- a/src/projects/upload-parts.test.osl +++ b/src/projects/upload-parts.test.osl @@ -19,7 +19,7 @@ def readFile(string path) object ( return {ok: true, data: json.parse(text.unwrap()).unwrap()} ) def writeFile(string path, object data) boolean ( - return fs.writeFile(path, json.stringify(data)) + return (fs.writeFile(path, json.stringify(data))).isOk() ) def randomString(number length) string ( return "r" * length diff --git a/src/rotur/rotur-badges.test.osl b/src/rotur/rotur-badges.test.osl index 903b41b..4f5a6f1 100644 --- a/src/rotur/rotur-badges.test.osl +++ b/src/rotur/rotur-badges.test.osl @@ -52,7 +52,7 @@ wait 0.5 testing.assert(profiles.sam.creatingStreak.count == 1 and profiles.sam.creatingStreak.day == 103, "a missed day starts the streak again") testing.assert(sent.contains("PUT /badges/streak/users/id-sam {\"progress\":1}"), "the first day sets progress 1: " ++ json.stringify(sent)) testing.assert(sent.contains("PUT /badges/streak/users/id-sam {\"progress\":2}"), "the next day sets progress 2") -testing.assert(sent.filter((any line) boolean -> line.toStr().contains("streak")).len == 3, "the same day isn't counted twice") +testing.assert(sent.filter(def(any line) boolean -> line.toStr().contains("streak")).len == 3, "the same day isn't counted twice") testing.assert(sent.contains("PUT /badges/chatty/users/id-sam {\"delta\":1}"), "a mapped event sends its delta") testing.assert(!json.stringify(sent).contains("student"), "classroom students are never sent") testing.assert(!json.stringify(sent).contains("remixer"), "a rule with neither delta nor progress is skipped, not sent as progress 0") diff --git a/src/storage/archive-security.test.osl b/src/storage/archive-security.test.osl index 0357b1d..d09abd6 100644 --- a/src/storage/archive-security.test.osl +++ b/src/storage/archive-security.test.osl @@ -35,7 +35,7 @@ def stageBytes(string kind, string name, byte[] content) ( def compressFixture(string kind) byte[] ( string outPath = fixtureDir ++ "/" ++ kind ++ ".zip" - testing.assert(zip.compress(fixtureDir ++ "/" ++ kind, outPath), "fixture compresses: " ++ kind) + testing.assert(zip.compress(fixtureDir ++ "/" ++ kind, outPath).isOk(), "fixture compresses: " ++ kind) return fs.readFileBytes(outPath) ) diff --git a/src/storage/asset-routing.osl b/src/storage/asset-routing.osl index af1ad27..1fb23c6 100644 --- a/src/storage/asset-routing.osl +++ b/src/storage/asset-routing.osl @@ -11,7 +11,7 @@ def assetUrlForLocation(string name, boolean localExists, string localAssetsBase def removeLocalAssetAfterUpload(string path, boolean uploadedToR2) boolean ( if uploadedToR2 and fs.exists(path) ( - return fs.remove(path) + return fs.remove(path).isOk() ) return true ) diff --git a/src/storage/backpack-policy.test.osl b/src/storage/backpack-policy.test.osl index a475771..eb92ab6 100644 --- a/src/storage/backpack-policy.test.osl +++ b/src/storage/backpack-policy.test.osl @@ -37,7 +37,7 @@ testing.assert(backpackFilterType(items, "").len == 3, "an empty filter keeps ev object split = backpackWithout(items, ["a", "missing"]) testing.assert(split.kept.len == 2, "unmatched ids leave items alone") testing.assert(split.removed.len == 1, "matched ids are removed") -testing.assert(backpackTotalBytes(split.removed.assert(array)) == 110, "removed bytes can be freed") +testing.assert(backpackTotalBytes(split.removed) == 110, "removed bytes can be freed") testing.assert(backpackPageSize("20") == 20, "page size is honoured") testing.assert(backpackPageSize("0") == maxBackpackPageSize, "zero falls back to the maximum") diff --git a/src/storage/backpack.osl b/src/storage/backpack.osl index a8ac47a..b47ff99 100644 --- a/src/storage/backpack.osl +++ b/src/storage/backpack.osl @@ -258,11 +258,11 @@ def removeBackpackItemsLocked(string userId, array ids) object ( sync.lock(backpackLockName(userId)) defer sync.unlock(backpackLockName(userId)) object split = backpackWithout(loadBackpackItems(userId), ids) - array removed = split.removed.assert(array) + array removed = split.removed if removed.len == 0 ( return {ok: true, removed: removed} ) - if !saveBackpackItems(userId, split.kept.assert(array)) ( + if !saveBackpackItems(userId, split.kept) ( return {ok: false} ) return {ok: true, removed: removed} diff --git a/src/storage/r2-snapshot-serving.test.osl b/src/storage/r2-snapshot-serving.test.osl index b296849..cc14e0b 100644 --- a/src/storage/r2-snapshot-serving.test.osl +++ b/src/storage/r2-snapshot-serving.test.osl @@ -78,7 +78,7 @@ def requestSnapshot(string key, boolean gzip, string etag) object ( gzipParam = "1" ) auto res = requests.get("http://127.0.0.1:18332/snap/" ++ url.escape(key), {query: {gzip: gzipParam}, headers: {"If-None-Match": etag, "Accept-Encoding": "identity"}}) - return {status: res.status, body: res.body, encoding: res.headers["Content-Encoding"] ?? "", type: res.headers["Content-Type"] ?? "", etag: res.headers["Etag"] ?? ""} + return {status: res.status, body: res.body, encoding: res.headers["Content-Encoding"], type: res.headers["Content-Type"], etag: res.headers["Etag"]} ) string plain = "{\"targets\":[],\"meta\":{\"name\":\"burger 🍔\"}}" diff --git a/src/storage/r2-upload-queue.osl b/src/storage/r2-upload-queue.osl index 0c25410..f73bdbe 100644 --- a/src/storage/r2-upload-queue.osl +++ b/src/storage/r2-upload-queue.osl @@ -104,7 +104,7 @@ def stageR2Blob(string key, BlobBody body, string contentType, string contentEnc boolean saved = true if !fs.exists(path) ( void fs.mkdir(parentDirOf(path), {recursive: true}) - saved = fs.writeFileBytes(path, body) + saved = fs.writeFileBytes(path, body).isOk() ) if saved and !r2Local ( saved = queueR2UploadLocked(key, contentType, contentEncoding) diff --git a/src/storage/r2-upload-queue.test.osl b/src/storage/r2-upload-queue.test.osl index 7666c99..c98c25c 100644 --- a/src/storage/r2-upload-queue.test.osl +++ b/src/storage/r2-upload-queue.test.osl @@ -26,7 +26,7 @@ def readFile(string path) object ( ) def writeFile(string path, object data) boolean ( - return fs.writeFile(path, json.stringify(data)) + return (fs.writeFile(path, json.stringify(data))).isOk() ) def localBlobPath(string key) string ( diff --git a/src/storage/r2.osl b/src/storage/r2.osl index 5d65e59..fca1f75 100644 --- a/src/storage/r2.osl +++ b/src/storage/r2.osl @@ -338,7 +338,7 @@ def r2PutEncoded(string key, BlobBody body, string contentType, string contentEn if r2Local ( string path = localBlobPath(key) void fs.mkdir(parentDirOf(path), {recursive: true}) - return fs.writeFileBytes(path, body) + return fs.writeFileBytes(path, body).isOk() ) string uploadType = if contentType == "" then "application/octet-stream" else contentType boolean stored = key != "" and r2Client.upload(key, body, {contentType: uploadType, contentEncoding: contentEncoding}) @@ -487,7 +487,7 @@ def copyStorageKeyToPath(string key, string outputPath) boolean ( if existing.isErr() ( return false ) - return fs.writeFileBytes(outputPath, existing.unwrap()) + return (fs.writeFileBytes(outputPath, existing.unwrap())).isOk() ) def copyProjectWorkspaceToPath(object project, string outputPath) boolean ( @@ -532,7 +532,7 @@ def copyStoredProjectJsonToPath(object project, string outputPath) boolean ( ) return copyFileReplacing(localPath, outputPath) ) - return zip.gzip(localPath, outputPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}) + return zip.gzip(localPath, outputPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}).isOk() ) if r2Local or project.jsonKey.toStr() == "" ( return false @@ -546,13 +546,13 @@ def copyStoredProjectJsonToPath(object project, string outputPath) boolean ( if fetched.body.toStr().toBytes().len > maxStoredProjectJsonBytes ( return false ) - return fs.writeFileBytes(outputPath, fetched.body) + return fs.writeFileBytes(outputPath, fetched.body).isOk() ) string plainPath = outputPath ++ ".plain" if !fs.writeFileBytes(plainPath, fetched.body) ( return false ) - boolean compressed = zip.gzip(plainPath, outputPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}) + boolean compressed = zip.gzip(plainPath, outputPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}).isOk() void fs.remove(plainPath) return compressed ) diff --git a/src/storage/storage-ledger.test.osl b/src/storage/storage-ledger.test.osl index d222180..1a35bd3 100644 --- a/src/storage/storage-ledger.test.osl +++ b/src/storage/storage-ledger.test.osl @@ -86,7 +86,7 @@ def readFile(string path) object ( ) def writeFile(string path, object data) boolean ( - return fs.writeFile(path, json.stringify(data)) + return (fs.writeFile(path, json.stringify(data))).isOk() ) def quotaPath(string username) string ( diff --git a/src/storage/storage.osl b/src/storage/storage.osl index c48db16..2009dd6 100644 --- a/src/storage/storage.osl +++ b/src/storage/storage.osl @@ -25,7 +25,7 @@ export { } def ensureDirectories() boolean ( - boolean res = fs.mkdir(projectsDir, {recursive: true}) + boolean res = fs.mkdir(projectsDir, {recursive: true}).isOk() res = res and fs.mkdir(usersDir, {recursive: true}) res = res and fs.mkdir(sessionsDir, {recursive: true}) res = res and fs.mkdir(commentsDir, {recursive: true}) @@ -285,7 +285,7 @@ def deleteProjectFile(string id) boolean ( if !isSafePathPart(id) ( return false ) - return fs.remove(projectsDir ++ id ++ ".json") + return fs.remove(projectsDir ++ id ++ ".json").isOk() ) def defaultProfile(string username) object ( @@ -405,7 +405,7 @@ def saveComments(string key, array comments) boolean ( if !fs.writeFile(tmpPath, out) ( return false ) - boolean ok = fs.rename(tmpPath, path) + boolean ok = fs.rename(tmpPath, path).isOk() if !ok ( void fs.remove(tmpPath) return false @@ -418,5 +418,5 @@ def appendComment(string key, object comment) boolean ( if !isSafePathPart(key) ( return false ) - return fs.appendFile(commentsDir ++ key ++ ".jsonl", json.stringify(comment) ++ "\n") + return (fs.appendFile(commentsDir ++ key ++ ".jsonl", json.stringify(comment) ++ "\n")).isOk() ) From 01c734ba3b36f4986c44ce758124ef276be70715 Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 28 Nov 2026 01:11:11 +0000 Subject: [PATCH 2/5] Build on OSL 24.0.1 Handle the results OSL 24 returns from db, fs, zip, json and r2 calls, rename requests timeoutMs to timeout and the s3 options to camelCase, and give the Rotur, storage ledger and Rotur app requests their 10 second timeouts in milliseconds, which OSL 24 reads timeout as. CI builds OSL at the 24.0.1 fixes this needed. --- .github/workflows/test.yml | 2 +- AGENTS.md | 2 +- README.md | 2 +- opal.json | 2 +- src/admin/admin-users.osl | 2 +- src/admin/errors.osl | 4 +- src/admin/errors.test.osl | 18 ++++----- src/admin/funnel-events.osl | 2 +- src/admin/project-moderation.osl | 2 +- src/auth/agreement.osl | 2 +- src/auth/user-identity.osl | 6 +-- src/classroom/classroom-billing.osl | 14 +++---- src/classroom/classroom-groups.osl | 8 ++-- src/classroom/classroom-legal.osl | 4 +- src/classroom/classroom-present.osl | 2 +- src/classroom/classroom-release.osl | 6 +-- src/classroom/classroom-schools.osl | 10 ++--- src/classroom/classroom-switch.test.osl | 2 +- src/classroom/classrooms.osl | 34 ++++++++-------- src/community/bounties.osl | 2 +- src/community/challenges.osl | 24 ++++++------ src/community/comments.osl | 2 +- src/community/community-user-records.osl | 4 +- src/community/development.osl | 6 +-- src/community/like-milestones.osl | 2 +- src/community/like-milestones.test.osl | 6 +-- src/community/news.osl | 2 +- src/community/notifications.osl | 2 +- src/community/playtime-diagnostics.osl | 8 ++-- src/community/project-feedback.osl | 4 +- src/community/releases.osl | 4 +- src/community/remote-milestones.osl | 4 +- src/community/roadmap.osl | 14 +++---- src/community/social.osl | 10 ++--- src/community/space-comments.osl | 12 +++--- src/community/space-memberships.osl | 4 +- src/community/space-responses.osl | 2 +- src/community/spaces.osl | 40 +++++++++---------- src/config/config.osl | 4 +- src/core/database.osl | 18 ++++----- src/core/utils.osl | 2 +- src/games/game-data.osl | 4 +- src/git/git-inspection.osl | 10 ++--- src/git/pulls.osl | 2 +- src/history/history-migration.test.osl | 2 +- src/projects/extensions.osl | 8 ++-- src/projects/project-read.osl | 4 +- src/projects/project-remix.osl | 4 +- src/projects/project-snapshots.osl | 4 +- src/projects/project-upload-files.osl | 4 +- src/projects/project-upload-history.osl | 8 ++-- src/projects/project-upload-receive.osl | 4 +- src/projects/project-upload.osl | 2 +- src/projects/upload-parts.osl | 4 +- src/rotur/rotur-app.osl | 2 +- src/storage/r2-snapshot-serving.test.osl | 2 +- src/storage/r2-upload-queue.osl | 2 +- src/storage/r2-upload-queue.test.osl | 2 +- src/storage/r2.osl | 8 ++-- src/storage/storage-ledger.osl | 2 +- src/storage/storage-usage.osl | 4 +- src/storage/storage.osl | 50 ++++++++++++------------ src/storage/thumbnail-access.osl | 2 +- 63 files changed, 217 insertions(+), 217 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 834ca04..e51ab3e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - name: Install OSL env: - OSL_COMMIT: aeb83e39b3f5638e4a366c4d9c6fa881f630e72c + OSL_COMMIT: 44dde5ba5120c295617392cf05d098bd4a4c4b36 run: | mkdir -p "$HOME/.local/bin" git clone --filter=blob:none https://git.rotur.dev/osl/.go /tmp/osl-source diff --git a/AGENTS.md b/AGENTS.md index 3ba9147..d847946 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # AGENTS.md -mistwarp-api is the OSL backend behind https://api.mistwarp.org/v1, for the MistWarp community site and editor (scratch-gui). It needs OSL 6.1. Community data is in SQLite (`data/community.db`), other state is JSON under `data/`, and project files are in Cloudflare R2. +mistwarp-api is the OSL backend behind https://api.mistwarp.org/v1, for the MistWarp community site and editor (scratch-gui). It needs OSL 24.0.1. Community data is in SQLite (`data/community.db`), other state is JSON under `data/`, and project files are in Cloudflare R2. ## Where code goes diff --git a/README.md b/README.md index ec8c23b..0329ad7 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ It runs at `https://api.mistwarp.org/v1`. The editor and community site are [scr ## Getting started -You need OSL 6.1. +You need OSL 24.0.1. ```sh cp .env.example .env diff --git a/opal.json b/opal.json index bfd38cd..e096d9d 100644 --- a/opal.json +++ b/opal.json @@ -1,6 +1,6 @@ { "name": "mistwarp-api", - "version": "1.7.0", + "version": "1.7.1", "main": "main.osl", "scripts": { "dev": ["osl", "run", "main.osl"], diff --git a/src/admin/admin-users.osl b/src/admin/admin-users.osl index 5b3c0f1..f78aa86 100644 --- a/src/admin/admin-users.osl +++ b/src/admin/admin-users.osl @@ -111,7 +111,7 @@ def unindexComment(string key, string cid) ( def migrateCommentIndex() boolean ( string migrationId = "migration:comment-index-v1" - if (diagnosticDocs.findById(migrationId) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( return true ) array files = fs.readDir(commentsDir).unwrapOr([]) diff --git a/src/admin/errors.osl b/src/admin/errors.osl index 9c30daf..1736602 100644 --- a/src/admin/errors.osl +++ b/src/admin/errors.osl @@ -336,7 +336,7 @@ def handleAdminResolveSiteError(*serve.Context c) ( def resolveSiteErrorLocked(*serve.Context c, string id, boolean resolved) object ( sync.lock("site-errors") defer sync.unlock("site-errors") - object entry = (errorDocs.findById(id) ?? {}) + object entry = (errorDocs.findById(id).unwrapOr(null) ?? {}) if entry.len == 0 ( c.notFound("error not found") return {found: false} @@ -369,7 +369,7 @@ def handleAdminDeleteSiteError(*serve.Context c) ( c.badRequest("error id is required") return ) - if (errorDocs.findById(id) ?? {}).len == 0 ( + if (errorDocs.findById(id).unwrapOr(null) ?? {}).len == 0 ( c.notFound("error not found") return ) diff --git a/src/admin/errors.test.osl b/src/admin/errors.test.osl index e9aeca9..2541be0 100644 --- a/src/admin/errors.test.osl +++ b/src/admin/errors.test.osl @@ -76,7 +76,7 @@ testing.assert(scrubbed.resolved == true and scrubbed.kind == "react" and scrubb errorDocs.insertOne({_id: "legacy", message: "m", url: "https://mistwarp.org/users/mist", username: "mist", userAgent: "x", projectId: "p1", created: timestamp, resolved: false}) pruneSiteErrors() -object legacy = errorDocs.findById("legacy") ?? {} +object legacy = errorDocs.findById("legacy").unwrapOr(null) ?? {} testing.assert(legacy.len > 0 and !legacy.contains("username") and legacy.url == "https://mistwarp.org/users/:id", "the sweep scrubs reports stored before this change") void deleteAllSiteErrors() @@ -84,7 +84,7 @@ for i 250 ( errorDocs.insertOne({_id: "e" ++ i.toStr(), resolved: i % 2 == 0, created: i}) ) testing.assert(deleteAllSiteErrors() == 250, "deletes beyond the 200-entry response limit") -testing.assert(errorDocs.count({}) == 0, "deletes both open and resolved errors") +testing.assert(errorDocs.count({}).unwrap() == 0, "deletes both open and resolved errors") testing.assert(deleteAllSiteErrors() == 0, "deleting an empty collection succeeds") testing.assert(siteErrorCutoff(100 * 86400000) == 93 * 86400000, "reports are kept for 7 days") @@ -93,9 +93,9 @@ errorDocs.insertOne({_id: "old", resolved: false, created: now - (8 * 86400000)} errorDocs.insertOne({_id: "edge", resolved: true, created: now - (6 * 86400000)}) errorDocs.insertOne({_id: "new", resolved: false, created: now}) sweepSiteErrors() -testing.assert((errorDocs.findById("old") ?? {}).len == 0, "the sweep deletes reports older than 7 days, resolved or not") -testing.assert((errorDocs.findById("edge") ?? {}).len > 0, "the sweep keeps reports younger than 7 days") -testing.assert((errorDocs.findById("new") ?? {}).len > 0, "the sweep keeps new reports") +testing.assert((errorDocs.findById("old").unwrapOr(null) ?? {}).len == 0, "the sweep deletes reports older than 7 days, resolved or not") +testing.assert((errorDocs.findById("edge").unwrapOr(null) ?? {}).len > 0, "the sweep keeps reports younger than 7 days") +testing.assert((errorDocs.findById("new").unwrapOr(null) ?? {}).len > 0, "the sweep keeps new reports") testing.assert(deleteAllSiteErrors() == 2, "only the expired report was swept") for i 1005 ( @@ -103,10 +103,10 @@ for i 1005 ( ) errorDocs.insertOne({_id: "stale", resolved: false, created: now - (200 * 86400000)}) pruneSiteErrors() -testing.assert(errorDocs.count({}) == 1000, "pruning keeps the newest 1000 reports") -testing.assert((errorDocs.findById("stale") ?? {}).len == 0, "pruning drops expired reports too") -testing.assert((errorDocs.findById("c1") ?? {}).len == 0, "pruning drops the oldest reports beyond the cap") -testing.assert((errorDocs.findById("c1005") ?? {}).len > 0, "pruning keeps the newest report") +testing.assert(errorDocs.count({}).unwrap() == 1000, "pruning keeps the newest 1000 reports") +testing.assert((errorDocs.findById("stale").unwrapOr(null) ?? {}).len == 0, "pruning drops expired reports too") +testing.assert((errorDocs.findById("c1").unwrapOr(null) ?? {}).len == 0, "pruning drops the oldest reports beyond the cap") +testing.assert((errorDocs.findById("c1005").unwrapOr(null) ?? {}).len > 0, "pruning keeps the newest report") void deleteAllSiteErrors() testing.assert(sweepSiteErrors(), "a sweep that works reports success") testDb.close() diff --git a/src/admin/funnel-events.osl b/src/admin/funnel-events.osl index 001631a..2e92e1d 100644 --- a/src/admin/funnel-events.osl +++ b/src/admin/funnel-events.osl @@ -4,7 +4,7 @@ def recordFunnelEvent(string key, number now) ( string id = "funnel:" ++ funnelDayKey(now) sync.lock("funnel-events") defer sync.unlock("funnel-events") - object doc = funnelDocs.findById(id) ?? {} + object doc = funnelDocs.findById(id).unwrapOr(null) ?? {} object counts = {} if doc.contains("counts") and doc.counts != null ( counts = doc.counts.assert(object) diff --git a/src/admin/project-moderation.osl b/src/admin/project-moderation.osl index 38a3bd0..4f2145a 100644 --- a/src/admin/project-moderation.osl +++ b/src/admin/project-moderation.osl @@ -226,7 +226,7 @@ def handleListShadowBans(*serve.Context c) ( for i projectIds.len ( string id = projectIds[i].toStr() object entry = projects[id].assertElse(object, {}) - object indexed = (projectSearchDocs.findById(id) ?? {}) + object indexed = (projectSearchDocs.findById(id).unwrapOr(null) ?? {}) projectRows.append({ id: id, title: if indexed.len > 0 then indexed.title else entry.title ?? "", diff --git a/src/auth/agreement.osl b/src/auth/agreement.osl index 63e01ab..eec739b 100644 --- a/src/auth/agreement.osl +++ b/src/auth/agreement.osl @@ -32,7 +32,7 @@ def saveAgreement(object data) boolean ( bool ok = writeFile(agreementMetaPath(), data) data.text = text if text != "" ( - if !fs.writeFile(agreementTextPath(), text) ( + if !fs.writeFile(agreementTextPath(), text).isOk() ( ok = false ) ) diff --git a/src/auth/user-identity.osl b/src/auth/user-identity.osl index 9668d2c..38fa459 100644 --- a/src/auth/user-identity.osl +++ b/src/auth/user-identity.osl @@ -502,13 +502,13 @@ def ensureUserIdentity(string userId, string username) ( userIdsCache.set("username:" ++ normalizeUsername(username), userId) ) -number roturRequestTimeoutSeconds = 10 +number roturRequestTimeoutMs = 10000 def roturServiceOptions() object ( if mistwarpRoturToken == "" ( - return {timeout: roturRequestTimeoutSeconds} + return {timeout: roturRequestTimeoutMs} ) - return {headers: {"Authorization": "Bearer " ++ mistwarpRoturToken}, timeout: roturRequestTimeoutSeconds} + return {headers: {"Authorization": "Bearer " ++ mistwarpRoturToken}, timeout: roturRequestTimeoutMs} ) def refreshUsernameForId(string userId) string ( diff --git a/src/classroom/classroom-billing.osl b/src/classroom/classroom-billing.osl index 03cf462..afa87aa 100644 --- a/src/classroom/classroom-billing.osl +++ b/src/classroom/classroom-billing.osl @@ -6,7 +6,7 @@ def stripeBillingConfigured() boolean ( def stripeRequest(string path, array fields) object ( object resp = requests.post("https://api.stripe.com/v1" ++ path, { - timeoutMs: 15000, + timeout: 15000, headers: { "Authorization": "Bearer " ++ stripeSecretKey, "Content-Type": "application/x-www-form-urlencoded" @@ -28,7 +28,7 @@ def stripeRequest(string path, array fields) object ( ) def classroomBillingInfo(string userId) object ( - object stored = (classroomPlanDocs.findById(userId) ?? {}) + object stored = (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}) boolean schoolManaged = schoolForTeacher(userId).len > 0 return { available: stripeBillingConfigured() and !schoolManaged, @@ -62,7 +62,7 @@ def startClassroomTrialLocked(*serve.Context c, string userId) boolean ( string lockName = "classroom-plan-" ++ userId sync.lock(lockName) defer sync.unlock(lockName) - object stored = (classroomPlanDocs.findById(userId) ?? {}) + object stored = (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}) if !classroomTrialAvailable(stored, false, timestamp) ( c.json(409, {ok: false, code: "trial_unavailable", error: "The free trial is for teachers who have not had a Classroom plan before."}) return false @@ -85,7 +85,7 @@ def handleClassroomCheckout(*serve.Context c) ( return ) string userId = contextString(c, "userId") - object stored = (classroomPlanDocs.findById(userId) ?? {}) + object stored = (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}) if classroomSubscriptionActive((stored.stripeStatus ?? "").toStr()) ( c.json(409, {ok: false, code: "already_subscribed", error: "You already have a Classroom subscription. Manage it from billing."}) return @@ -128,7 +128,7 @@ def handleClassroomBillingPortal(*serve.Context c) ( c.json(503, {ok: false, code: "billing_unavailable", error: "Online payment is not set up yet. Contact MistWarp support to change your plan."}) return ) - object stored = (classroomPlanDocs.findById(contextString(c, "userId")) ?? {}) + object stored = (classroomPlanDocs.findById(contextString(c, "userId")).unwrapOr(null) ?? {}) string customerId = (stored.stripeCustomerId ?? "").toStr() if customerId == "" ( c.json(404, {ok: false, code: "no_billing_account", error: "You have not bought a plan online yet."}) @@ -146,7 +146,7 @@ def storeStripePlan(string userId, object update, number eventCreated) ( string lockName = "classroom-plan-" ++ userId sync.lock(lockName) defer sync.unlock(lockName) - object stored = (classroomPlanDocs.findById(userId) ?? {}) + object stored = (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}) if stored.len == 0 ( stored = {_id: userId} ) @@ -168,7 +168,7 @@ def applyStripeSubscription(object subscription, number eventCreated, boolean de return ) string subscriptionId = (subscription.id ?? "").toStr() - if !stripeEventMayChangePlan((classroomPlanDocs.findById(userId) ?? {}), subscriptionId) ( + if !stripeEventMayChangePlan((classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}), subscriptionId) ( return ) object plan = classroomPlanFromSubscription(subscription, [stripeSeatPackPrice, stripeSeatPackPriceYearly]) diff --git a/src/classroom/classroom-groups.osl b/src/classroom/classroom-groups.osl index c8ae84f..86761ae 100644 --- a/src/classroom/classroom-groups.osl +++ b/src/classroom/classroom-groups.osl @@ -48,7 +48,7 @@ def groupForSubmission(object submission) object ( if groupId == "" ( return {} ) - object group = (classroomGroupDocs.findById(groupId) ?? {}) + object group = (classroomGroupDocs.findById(groupId).unwrapOr(null) ?? {}) if group.len == 0 ( return {} ) @@ -103,14 +103,14 @@ def handleCreateClassGroup(*serve.Context c) ( object assignment = {} string assignmentId = (body.assignmentId ?? "").toStr() if assignmentId != "" ( - assignment = (assignmentDocs.findById(assignmentId) ?? {}) + assignment = (assignmentDocs.findById(assignmentId).unwrapOr(null) ?? {}) if assignment.len == 0 or assignment.classId.toStr() != classId ( c.badRequest("choose an assignment from this class") return ) for i students.len ( object student = students[i].assert(object) - if (submissionDocs.findById(assignmentId ++ ":" ++ student["_id"].toStr()) ?? {}).len > 0 ( + if (submissionDocs.findById(assignmentId ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}).len > 0 ( c.json(409, {ok: false, code: "already_started", error: student.displayName.toStr() ++ " has already started this assignment on their own."}) return ) @@ -184,7 +184,7 @@ def handleDeleteClassGroup(*serve.Context c) ( if classDoc.len == 0 ( return ) - object group = (classroomGroupDocs.findById(c.param("gid")) ?? {}) + object group = (classroomGroupDocs.findById(c.param("gid")).unwrapOr(null) ?? {}) if group.len == 0 or group.classId.toStr() != classDoc["_id"].toStr() ( c.notFound("group not found") return diff --git a/src/classroom/classroom-legal.osl b/src/classroom/classroom-legal.osl index b423c3d..e57cc64 100644 --- a/src/classroom/classroom-legal.osl +++ b/src/classroom/classroom-legal.osl @@ -3,7 +3,7 @@ export { } def classroomTermsRecord(string userId) object ( - return (classroomTermsDocs.findById(userId) ?? {}) + return (classroomTermsDocs.findById(userId).unwrapOr(null) ?? {}) ) def classroomTermsStatus(string userId) object ( @@ -229,7 +229,7 @@ def handleAdminPurgeClassroom(*serve.Context c) ( string target = "" string schoolId = (body.schoolId ?? "").toStr() if schoolId != "" ( - object school = (schoolDocs.findById(schoolId) ?? {}) + object school = (schoolDocs.findById(schoolId).unwrapOr(null) ?? {}) if school.len == 0 ( c.badRequest("school not found") return diff --git a/src/classroom/classroom-present.osl b/src/classroom/classroom-present.osl index af9b5f8..ae4b627 100644 --- a/src/classroom/classroom-present.osl +++ b/src/classroom/classroom-present.osl @@ -5,7 +5,7 @@ export { number classroomPresentationLifetimeMs = 14400000 def activePresentationForProject(string projectId) object ( - object presentation = (classroomPresentationDocs.findById(projectId) ?? {}) + object presentation = (classroomPresentationDocs.findById(projectId).unwrapOr(null) ?? {}) if presentation.len == 0 or (presentation.expiresAt ?? 0).toNum() <= timestamp ( return {} ) diff --git a/src/classroom/classroom-release.osl b/src/classroom/classroom-release.osl index 122f60c..c7a1076 100644 --- a/src/classroom/classroom-release.osl +++ b/src/classroom/classroom-release.osl @@ -6,7 +6,7 @@ def loadClassroomClaim(string code) object ( if code == "" ( return {} ) - return (classroomClaimDocs.findById(code) ?? {}) + return (classroomClaimDocs.findById(code).unwrapOr(null) ?? {}) ) def claimIsUsable(object claim, number now) boolean ( @@ -46,7 +46,7 @@ def handleReleaseStudent(*serve.Context c) ( string code = "" for _ 20 ( string candidate = randomFromAlphabet(classCodeAlphabet, 10) - if code == "" and (classroomClaimDocs.findById(candidate) ?? {}).len == 0 ( + if code == "" and (classroomClaimDocs.findById(candidate).unwrapOr(null) ?? {}).len == 0 ( code = candidate ) ) @@ -82,7 +82,7 @@ def handleCancelStudentRelease(*serve.Context c) ( ) def usableClaimOrFail(*serve.Context c) object ( - object claim = (classroomClaimDocs.findById(normalizeClassCode(c.param("code"))) ?? {}) + object claim = (classroomClaimDocs.findById(normalizeClassCode(c.param("code"))).unwrapOr(null) ?? {}) object student = {} if claimIsUsable(claim, timestamp) ( student = loadStudent(claim.studentId.toStr()) diff --git a/src/classroom/classroom-schools.osl b/src/classroom/classroom-schools.osl index 6650022..dc35c0e 100644 --- a/src/classroom/classroom-schools.osl +++ b/src/classroom/classroom-schools.osl @@ -40,7 +40,7 @@ def classroomPlanKey(string ownerId) string ( ) def planMemberIds(string key) array ( - object school = (schoolDocs.findById(key) ?? {}) + object school = (schoolDocs.findById(key).unwrapOr(null) ?? {}) if school.len == 0 ( return [key] ) @@ -72,7 +72,7 @@ def schoolTeacherRows(object school) array ( array classes = classesOwnedBy(teacherId) number students = 0 for j classes.len ( - students += studentDocs.where("classId", "==", classes[j].assert(object)["_id"].toStr()).count() + students += studentDocs.where("classId", "==", classes[j].assert(object)["_id"].toStr()).count().unwrap() ) rows.append({userId: teacherId, username: usernameForId(teacherId), isAdmin: isSchoolAdmin(school, teacherId), classes: classes.len, students: students}) ) @@ -212,7 +212,7 @@ def handleGetSchoolAudit(*serve.Context c) ( array classIds = schoolClassIds(school) array events = [] for i classIds.len ( - events ++= classroomAuditDocs.where("classId", "==", classIds[i].toStr()).sort("at", "desc").limit(500).all() + events ++= classroomAuditDocs.where("classId", "==", classIds[i].toStr()).sort("at", "desc").limit(500).all().unwrap() ) events.sortBy("at", "descending") c.json(200, {ok: true, events: paginate(events, 0, clampNumber(c.queryInt("limit", 200), 1, 2000))}) @@ -264,7 +264,7 @@ def handleAdminListSchools(*serve.Context c) ( for i schools.len ( object school = schools[i].assert(object) string key = school["_id"].toStr() - rows.append({id: key, name: school.name, admins: (school.adminIds ?? []).assertElse(array, []).map(def(any id) any -> usernameForId(id.toStr())), plan: effectiveClassroomPlan((classroomPlanDocs.findById(key) ?? {}), timestamp)}) + rows.append({id: key, name: school.name, admins: (school.adminIds ?? []).assertElse(array, []).map(def(any id) any -> usernameForId(id.toStr())), plan: effectiveClassroomPlan((classroomPlanDocs.findById(key).unwrapOr(null) ?? {}), timestamp)}) ) c.json(200, {ok: true, schools: rows}) ) @@ -299,5 +299,5 @@ def handleAdminCreateSchool(*serve.Context c) ( updatedAt: timestamp }) invalidateClassroomPool(adminId) - c.json(201, {ok: true, school: {id: id, name: name}, plan: effectiveClassroomPlan((classroomPlanDocs.findById(id) ?? {}), timestamp)}) + c.json(201, {ok: true, school: {id: id, name: name}, plan: effectiveClassroomPlan((classroomPlanDocs.findById(id).unwrapOr(null) ?? {}), timestamp)}) ) diff --git a/src/classroom/classroom-switch.test.osl b/src/classroom/classroom-switch.test.osl index d73576a..3e8ea75 100644 --- a/src/classroom/classroom-switch.test.osl +++ b/src/classroom/classroom-switch.test.osl @@ -46,7 +46,7 @@ def loadStudent(string id) object ( ) def loadClass(string id) object ( - return (classDocs.findById(id) ?? {}) + return (classDocs.findById(id).unwrapOr(null) ?? {}) ) void classDocs.insertOne({_id: "cls_admin", code: "ADMIN234", ownerId: "u_mist", owner: "mist"}) diff --git a/src/classroom/classrooms.osl b/src/classroom/classrooms.osl index 1f82f39..1a47af5 100644 --- a/src/classroom/classrooms.osl +++ b/src/classroom/classrooms.osl @@ -19,7 +19,7 @@ def randomFromAlphabet(string alphabet, number length) string ( def generateClassCode() string ( for _ 20 ( string code = randomFromAlphabet(classCodeAlphabet, 8) - if classDocs.where("code", "==", code).count() == 0 ( + if classDocs.where("code", "==", code).count().unwrap() == 0 ( return code ) ) @@ -29,7 +29,7 @@ def generateClassCode() string ( def generateClassSlug() string ( for _ 20 ( string slug = randomFromAlphabet("abcdefghjkmnpqrstuvwxyz23456789", 5) - if classDocs.where("slug", "==", slug).count() == 0 ( + if classDocs.where("slug", "==", slug).count().unwrap() == 0 ( return slug ) ) @@ -54,14 +54,14 @@ def loadClass(string id) object ( if id == "" ( return {} ) - return (classDocs.findById(id) ?? {}) + return (classDocs.findById(id).unwrapOr(null) ?? {}) ) def loadStudent(string id) object ( if !isStudentUserId(id) ( return {} ) - return (studentDocs.findById(id) ?? {}) + return (studentDocs.findById(id).unwrapOr(null) ?? {}) ) def studentForUsername(string username) object ( @@ -120,13 +120,13 @@ def studentsForPlanOwner(string ownerId) array ( array classes = classesForPlanOwner(ownerId) for i classes.len ( object classDoc = classes[i].assert(object) - students ++= studentDocs.where("classId", "==", classDoc["_id"].toStr()).all() + students ++= studentDocs.where("classId", "==", classDoc["_id"].toStr()).all().unwrap() ) return students ) def classroomPlanFor(string ownerId) object ( - return effectiveClassroomPlan((classroomPlanDocs.findById(classroomPlanKey(ownerId)) ?? {}), timestamp) + return effectiveClassroomPlan((classroomPlanDocs.findById(classroomPlanKey(ownerId)).unwrapOr(null) ?? {}), timestamp) ) def classroomPlanLock(string ownerId) string ( @@ -411,7 +411,7 @@ def handleDeleteClass(*serve.Context c) ( object classDoc = ownedClassOrFail(c) if classDoc.len == 0 return string classId = classDoc["_id"].toStr() - if studentDocs.where("classId", "==", classId).count() > 0 ( + if studentDocs.where("classId", "==", classId).count().unwrap() > 0 ( c.json(409, {ok: false, code: "class_not_empty", error: "Move or delete every student before deleting the class."}) return ) @@ -976,7 +976,7 @@ def handleCreateAssignment(*serve.Context c) ( ) def classAssignmentOrFail(*serve.Context c, object classDoc) object ( - object assignment = (assignmentDocs.findById(c.param("aid")) ?? {}) + object assignment = (assignmentDocs.findById(c.param("aid")).unwrapOr(null) ?? {}) if assignment.len == 0 or assignment.classId.toStr() != classDoc["_id"].toStr() ( c.notFound("assignment not found") return {} @@ -994,7 +994,7 @@ def handleGetAssignment(*serve.Context c) ( array rows = [] for i students.len ( object student = students[i].assert(object) - object submission = (submissionDocs.findById(assignmentId ++ ":" ++ student["_id"].toStr()) ?? {}) + object submission = (submissionDocs.findById(assignmentId ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}) rows.append({ student: {id: student["_id"], displayName: student.displayName}, submission: if submission.len == 0 then null else submission, @@ -1031,7 +1031,7 @@ def handleReviewSubmission(*serve.Context c) ( if classDoc.len == 0 return object assignment = classAssignmentOrFail(c, classDoc) if assignment.len == 0 return - object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ c.param("sid")) ?? {}) + object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ c.param("sid")).unwrapOr(null) ?? {}) if submission.len == 0 ( c.notFound("this student has not started the assignment") return @@ -1076,7 +1076,7 @@ def studentAssignmentRows(object student) array ( array rows = [] for i assignments.len ( object assignment = assignments[i].assert(object) - object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()) ?? {}) + object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}) rows.append({ id: assignment["_id"], title: assignment.title, @@ -1118,7 +1118,7 @@ def handleGetStudentClassroom(*serve.Context c) ( def studentAssignmentOrFail(*serve.Context c) object ( object student = loadStudent(contextString(c, "userId")) - object assignment = (assignmentDocs.findById(c.param("aid")) ?? {}) + object assignment = (assignmentDocs.findById(c.param("aid")).unwrapOr(null) ?? {}) if student.len == 0 or assignment.len == 0 or assignment.classId.toStr() != student.classId.toStr() ( c.notFound("assignment not found") return {} @@ -1189,7 +1189,7 @@ def startSubmissionLocked(*serve.Context c, object student, object assignment, s string lockName = "classroom-submission-" ++ submissionId sync.lock(lockName) defer sync.unlock(lockName) - object existing = (submissionDocs.findById(submissionId) ?? {}) + object existing = (submissionDocs.findById(submissionId).unwrapOr(null) ?? {}) if existing.len > 0 ( auto loaded = loadProject(existing.projectId.toStr()) if loaded.ok ( @@ -1243,7 +1243,7 @@ def handleTurnInAssignment(*serve.Context c) ( if found.len == 0 return object student = found.student.assert(object) object assignment = found.assignment.assert(object) - object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()) ?? {}) + object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}) if submission.len == 0 or !submissionCanTurnIn(submission) ( c.badRequest("start the assignment before turning it in") return @@ -1274,7 +1274,7 @@ def handleUnsubmitAssignment(*serve.Context c) ( if found.len == 0 return object student = found.student.assert(object) object assignment = found.assignment.assert(object) - object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()) ?? {}) + object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}) if submission.len == 0 or !submissionCanUnsubmit(submission) ( c.badRequest("this work is not waiting for your teacher") return @@ -1359,7 +1359,7 @@ def handleAdminGetClassroomPlan(*serve.Context c) ( c.badRequest("Rotur user not found") return ) - c.json(200, {ok: true, username: usernameForId(userId), stored: (classroomPlanDocs.findById(userId) ?? {}), plan: classroomPlanFor(userId), usage: classroomUsage(userId)}) + c.json(200, {ok: true, username: usernameForId(userId), stored: (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}), plan: classroomPlanFor(userId), usage: classroomUsage(userId)}) ) def handleAdminSetClassroomPlan(*serve.Context c) ( @@ -1367,7 +1367,7 @@ def handleAdminSetClassroomPlan(*serve.Context c) ( string userId = "" string schoolId = (body.schoolId ?? "").toStr() if schoolId != "" ( - if (schoolDocs.findById(schoolId) ?? {}).len == 0 ( + if (schoolDocs.findById(schoolId).unwrapOr(null) ?? {}).len == 0 ( c.badRequest("school not found") return ) diff --git a/src/community/bounties.osl b/src/community/bounties.osl index a15f7b6..09ba981 100644 --- a/src/community/bounties.osl +++ b/src/community/bounties.osl @@ -79,7 +79,7 @@ def handleJoinBounty(*serve.Context c) ( def handleLeaveBounty(*serve.Context c) ( string id = bountyWorkerId(c.param("id"), contextString(c, "userId")) - if bountyWorkerDocs.exists({_id: id}) ( + if bountyWorkerDocs.exists({_id: id}).unwrap() ( void bountyWorkerDocs.deleteOne({_id: id}) ) c.json(200, {ok: true, workers: bountyWorkers(c.param("id"), contextString(c, "username"))}) diff --git a/src/community/challenges.osl b/src/community/challenges.osl index 327d73d..3513598 100644 --- a/src/community/challenges.osl +++ b/src/community/challenges.osl @@ -208,7 +208,7 @@ def challengeWinner(object space, array projects) object ( ) def handleInviteChallengeJudge(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or space.kind.toStr() != "challenge" ( c.notFound("challenge not found") return @@ -223,7 +223,7 @@ def handleInviteChallengeJudge(*serve.Context c) ( ) string requested = requestJSON(c).username.toStr().strip() string usernameKey = normalizeUsername(requested) - object profile = (profileSearchDocs.findById(usernameKey) ?? {}) + object profile = (profileSearchDocs.findById(usernameKey).unwrapOr(null) ?? {}) if usernameKey == "" or profile.len == 0 ( c.notFound("user not found") return @@ -243,7 +243,7 @@ def handleInviteChallengeJudge(*serve.Context c) ( ) def handleJoinChallenge(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or space.kind.toStr() != "challenge" or !canViewSpace(space, c) ( c.notFound("challenge not found") return @@ -267,7 +267,7 @@ def handleJoinChallenge(*serve.Context c) ( ) def handleLeaveChallenge(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or space.kind.toStr() != "challenge" ( c.notFound("challenge not found") return @@ -284,7 +284,7 @@ def handleLeaveChallenge(*serve.Context c) ( ) array ids = spaceProjectIds(space) for i ids.len ( - object project = (projectSearchDocs.findById(ids[i].toStr()) ?? {}) + object project = (projectSearchDocs.findById(ids[i].toStr()).unwrapOr(null) ?? {}) if project.len > 0 and searchEntryOwnedByContext(project, c) ( c.badRequest("remove your submission before leaving the challenge") return @@ -297,7 +297,7 @@ def handleLeaveChallenge(*serve.Context c) ( ) def handleRespondChallengeJudgeInvite(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !isChallengeJudgeInvitee(space, contextString(c, "username")) ( c.notFound("judge invitation not found") return @@ -325,7 +325,7 @@ def handleRespondChallengeJudgeInvite(*serve.Context c) ( ) def handleRemoveChallengeJudge(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canManageSpace(space, c) ( c.forbidden("you cannot manage this challenge") return @@ -365,7 +365,7 @@ def validChallengeCriterion(object space, string criterionId) boolean ( ) def handleScoreChallengeEntry(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) string projectId = c.param("project") if space.len == 0 or space.kind.toStr() != "challenge" or !spaceProjectIds(space).contains(projectId) ( c.notFound("challenge entry not found") @@ -379,7 +379,7 @@ def handleScoreChallengeEntry(*serve.Context c) ( c.badRequest("judging is not open") return ) - object project = (projectSearchDocs.findById(projectId) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) if project.len > 0 and searchEntryOwnedByContext(project, c) ( c.forbidden("you cannot score your own entry") return @@ -424,7 +424,7 @@ def handleScoreChallengeEntry(*serve.Context c) ( ) def handleVoteChallengeEntry(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) string projectId = c.param("project") if space.len == 0 or space.kind.toStr() != "challenge" or !spaceProjectIds(space).contains(projectId) ( c.notFound("challenge entry not found") @@ -434,7 +434,7 @@ def handleVoteChallengeEntry(*serve.Context c) ( c.badRequest("community voting is not open") return ) - object project = (projectSearchDocs.findById(projectId) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) if project.len > 0 and searchEntryOwnedByContext(project, c) ( c.forbidden("you cannot vote for your own entry") return @@ -460,7 +460,7 @@ def handleVoteChallengeEntry(*serve.Context c) ( ) def handlePublishChallengeResults(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or space.kind.toStr() != "challenge" or !canManageSpace(space, c) ( c.forbidden("you cannot manage this challenge") return diff --git a/src/community/comments.osl b/src/community/comments.osl index acd9a1b..d87bec9 100644 --- a/src/community/comments.osl +++ b/src/community/comments.osl @@ -394,7 +394,7 @@ def commentPage(array allComments,*serve.Context c) object ( ) number totalRoots = roots.len number requestedLimit = c.queryInt("limit", 0) - if requestedLimit <= 0 or c.queryBool("all", false) ( + if requestedLimit <= 0 or c.queryBool("all", false).unwrapOr(false) ( return {comments: comments, totalRoots: totalRoots, nextOffset: totalRoots, issueCounts: issueCounts} ) number offset = clampNumber(c.queryInt("offset", 0), 0, totalRoots) diff --git a/src/community/community-user-records.osl b/src/community/community-user-records.osl index 474b9d9..d26853b 100644 --- a/src/community/community-user-records.osl +++ b/src/community/community-user-records.osl @@ -231,7 +231,7 @@ def renameUserCommunityRecords(string oldKey, string newKey, string newName) boo if normalizeUsername(playtime.username.toStr()) == oldKey ( string oldId = playtime["_id"].toStr() string newId = playtime.projectId.toStr() ++ ":" ++ newKey - object existing = (playtimeDocs.findById(newId) ?? {}) + object existing = (playtimeDocs.findById(newId).unwrapOr(null) ?? {}) if existing.len > 0 and newId != oldId ( playtime.duration = playtime.duration.toNum() + existing.duration.toNum() ) @@ -240,7 +240,7 @@ def renameUserCommunityRecords(string oldKey, string newKey, string newName) boo putDocument(playtimeDocs, newId, playtime) ) ) - object session = (playtimeSessionDocs.findById(oldKey) ?? {}) + object session = (playtimeSessionDocs.findById(oldKey).unwrapOr(null) ?? {}) if session.len > 0 ( session.username = newName void playtimeSessionDocs.deleteOne({_id: oldKey}) diff --git a/src/community/development.osl b/src/community/development.osl index 65b33bd..4658f70 100644 --- a/src/community/development.osl +++ b/src/community/development.osl @@ -31,7 +31,7 @@ def nowSeconds() number ( ) def developmentQuota() object ( - object stored = (developmentDocs.findById("quota") ?? {}) + object stored = (developmentDocs.findById("quota").unwrapOr(null) ?? {}) if stored.len == 0 ( return {remaining: -1, reset: 0} ) @@ -46,7 +46,7 @@ def storeDevelopmentQuota(object quota) ( def githubSearchPulls(string query, number limit) object ( string endpoint = "https://api.github.com/search/issues?q=" ++ url.escape(query) ++ "&sort=updated&order=desc&per_page=" ++ limit.toStr() - object response = requests.get(endpoint, {headers: githubHeaders(), timeoutMs: 10000, maxBytes: 8388608}).unwrapOr({body: null, error: "request failed", headers: {}, raw: null, status: 0, success: false}) + object response = requests.get(endpoint, {headers: githubHeaders(), timeout: 10000, maxBytes: 8388608}).unwrapOr({body: null, error: "request failed", headers: {}, raw: null, status: 0, success: false}) object headers = object(response.headers) number status = response.status if status == 403 or status == 429 ( @@ -85,7 +85,7 @@ def developmentSnapshot() object ( if developmentCache.has("pulls") ( return developmentCache.get("pulls").assertElse(object, {pulls: [], updated: 0}) ) - object stored = (developmentDocs.findById("pulls") ?? {}) + object stored = (developmentDocs.findById("pulls").unwrapOr(null) ?? {}) if stored.len == 0 ( return {pulls: [], updated: 0} ) diff --git a/src/community/like-milestones.osl b/src/community/like-milestones.osl index 9b0bf9b..e49214e 100644 --- a/src/community/like-milestones.osl +++ b/src/community/like-milestones.osl @@ -14,7 +14,7 @@ def notifyLikeMilestones(string target, string kind, string contentId, number be string lockName = "like-milestone:" ++ key sync.lock(lockName) defer sync.unlock(lockName) - object previous = (likeMilestoneDocs.findById(key) ?? {}) + object previous = (likeMilestoneDocs.findById(key).unwrapOr(null) ?? {}) number notifiedThrough = (previous.notifiedThrough ?? 0).toNum() array milestones = crossedLikeMilestones(before, after, notifiedThrough) for i milestones.len ( diff --git a/src/community/like-milestones.test.osl b/src/community/like-milestones.test.osl index ed83964..9046d21 100644 --- a/src/community/like-milestones.test.osl +++ b/src/community/like-milestones.test.osl @@ -55,8 +55,8 @@ def putDocument(*db.Collection collection, string id, object value) boolean ( return false ) value["_id"] = id - if collection.exists({_id: id}) ( - return collection.replaceOne({_id: id}, value) == 1 + if collection.exists({_id: id}).unwrap() ( + return collection.replaceOne({_id: id}, value).unwrap() == 1 ) return collection.insertOne(value).isOk() ) @@ -136,7 +136,7 @@ syncFollowerMilestones("mist") testing.assert(sent.len == 13 and sent[13].data.milestone == 50, "follower milestones use the profile's count, private followers included") testing.assert(sent[13].data.path == "/users/mist", "follower milestones link to the profile") syncFollowerMilestones("hidden") -testing.assert(sent.len == 13 and (likeMilestoneDocs.findById("observed:followers:hidden") ?? {}).len == 0, "a profile that hides its count records nothing") +testing.assert(sent.len == 13 and (likeMilestoneDocs.findById("observed:followers:hidden").unwrapOr(null) ?? {}).len == 0, "a profile that hides its count records nothing") milestoneDb.close() void fs.remove(path) void fs.remove(path ++ "-wal") diff --git a/src/community/news.osl b/src/community/news.osl index 01da235..3cd5fac 100644 --- a/src/community/news.osl +++ b/src/community/news.osl @@ -421,7 +421,7 @@ def handleViewNews(*serve.Context c) ( def migratePolicyNewsPosts() boolean ( string migrationId = "migration:news-policy-posts-v2" - if (diagnosticDocs.findById(migrationId) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( return true ) array titles = [ diff --git a/src/community/notifications.osl b/src/community/notifications.osl index 0840619..2a9ee89 100644 --- a/src/community/notifications.osl +++ b/src/community/notifications.osl @@ -319,7 +319,7 @@ def postRoturNotification(string target, string targetId, string actor, string a requestBody.actor_id = actorId ) object resp = requests.post(roturBase ++ "/v2/notifications", { - timeoutMs: 5000, + timeout: 5000, headers: notifyHeaders(), body: json.stringify(requestBody) }).unwrapOr({body: null, error: "request failed", headers: {}, raw: null, status: 0, success: false}) diff --git a/src/community/playtime-diagnostics.osl b/src/community/playtime-diagnostics.osl index 34596ee..ad94ca0 100644 --- a/src/community/playtime-diagnostics.osl +++ b/src/community/playtime-diagnostics.osl @@ -14,7 +14,7 @@ def playtimeIdentity(string username) string ( def beginPlaytimeSession(string projectId, string username, string sessionId) boolean ( string userId = userIdForUsername(username) string identityKey = playtimeIdentity(username) - object session = (playtimeSessionDocs.findById(sessionId) ?? {}) + object session = (playtimeSessionDocs.findById(sessionId).unwrapOr(null) ?? {}) if session.len == 0 or session.projectId.toStr() != projectId or timestamp - session.lastSeen.toNum() > 120000 ( putDocument(playtimeSessionDocs, sessionId, { _id: sessionId, @@ -39,7 +39,7 @@ def touchRecentProjectActivity(string projectId, string username) boolean ( string playtimeLock = "playtime:" ++ playtimeId sync.lock(playtimeLock) defer sync.unlock(playtimeLock) - object playtime = (playtimeDocs.findById(playtimeId) ?? {}) + object playtime = (playtimeDocs.findById(playtimeId).unwrapOr(null) ?? {}) if playtime.len == 0 ( playtime = {_id: playtimeId, projectId: projectId, username: username, userId: userId, duration: 0, updated: timestamp} ) else ( @@ -54,7 +54,7 @@ def touchRecentProjectActivity(string projectId, string username) boolean ( def creditPlaytimeSession(string projectId, string username, string sessionId, boolean finished) number ( string userId = userIdForUsername(username) - object session = (playtimeSessionDocs.findById(sessionId) ?? {}) + object session = (playtimeSessionDocs.findById(sessionId).unwrapOr(null) ?? {}) if session.len == 0 or session.projectId.toStr() != projectId ( return 0 ) @@ -78,7 +78,7 @@ def creditPlaytimeLocked(string playtimeId, string projectId, string username, s string playtimeLock = "playtime:" ++ playtimeId sync.lock(playtimeLock) defer sync.unlock(playtimeLock) - object playtime = (playtimeDocs.findById(playtimeId) ?? {}) + object playtime = (playtimeDocs.findById(playtimeId).unwrapOr(null) ?? {}) if playtime.len == 0 ( playtime = {_id: playtimeId, projectId: projectId, username: username, userId: userId, duration: 0, updated: timestamp} ) diff --git a/src/community/project-feedback.osl b/src/community/project-feedback.osl index f3967ae..6fd0af9 100644 --- a/src/community/project-feedback.osl +++ b/src/community/project-feedback.osl @@ -43,7 +43,7 @@ def handleUpdateProjectFeedback(*serve.Context c) ( c.forbidden("not your project") return ) - object feedback = (feedbackDocs.findById(c.param("feedback")) ?? {}) + object feedback = (feedbackDocs.findById(c.param("feedback")).unwrapOr(null) ?? {}) if feedback.len == 0 or feedback.projectId.toStr() != c.param("id") ( c.notFound("feedback not found") return @@ -144,7 +144,7 @@ def handleSaveProjectReview(*serve.Context c) ( reviewerId = normalizeUsername(contextString(c, "username")) ) string reviewId = project.id.toStr() ++ ":" ++ reviewerId - object existing = (reviewDocs.findById(reviewId) ?? {}) + object existing = (reviewDocs.findById(reviewId).unwrapOr(null) ?? {}) number created = timestamp if existing.len > 0 ( created = existing.created.toNum() diff --git a/src/community/releases.osl b/src/community/releases.osl index f549070..927f65d 100644 --- a/src/community/releases.osl +++ b/src/community/releases.osl @@ -127,7 +127,7 @@ def handleCreateRelease(*serve.Context c) ( ) def handleGetReleaseProjectJson(*serve.Context c) ( - object release = (releaseDocs.findById(c.param("release")) ?? {}) + object release = (releaseDocs.findById(c.param("release")).unwrapOr(null) ?? {}) if release.len == 0 or release.projectId.toStr() != c.param("id") ( c.notFound("release not found") return @@ -168,7 +168,7 @@ def handleDeleteRelease(*serve.Context c) ( c.forbidden("not your project") return ) - object release = (releaseDocs.findById(c.param("release")) ?? {}) + object release = (releaseDocs.findById(c.param("release")).unwrapOr(null) ?? {}) if release.len == 0 or release.projectId.toStr() != project.id.toStr() ( c.notFound("release not found") return diff --git a/src/community/remote-milestones.osl b/src/community/remote-milestones.osl index 3bd36c5..e51b5eb 100644 --- a/src/community/remote-milestones.osl +++ b/src/community/remote-milestones.osl @@ -9,7 +9,7 @@ def remoteMilestoneData(string path) object ( ) def milestoneDataFromUrl(string endpoint) object ( - object response = requests.get(endpoint, {timeoutMs: 5000, maxBytes: 2097152}).unwrapOr({body: null, error: "request failed", headers: {}, raw: null, status: 0, success: false}) + object response = requests.get(endpoint, {timeout: 5000, maxBytes: 2097152}).unwrapOr({body: null, error: "request failed", headers: {}, raw: null, status: 0, success: false}) if response.status != 200 ( return {} ) @@ -24,7 +24,7 @@ def observeRemoteMilestone(string target, string kind, string id, number count, string key = "observed:" ++ kind ++ ":" ++ id sync.lock(key) defer sync.unlock(key) - object previous = (likeMilestoneDocs.findById(key) ?? {}) + object previous = (likeMilestoneDocs.findById(key).unwrapOr(null) ?? {}) number before = count - 1 if previous.contains("count") ( before = previous.count.toNum() diff --git a/src/community/roadmap.osl b/src/community/roadmap.osl index 4a7b28b..b8fdd0d 100644 --- a/src/community/roadmap.osl +++ b/src/community/roadmap.osl @@ -102,7 +102,7 @@ def handleVoteIdea(*serve.Context c) ( ) def handleVoteIdeaLocked(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -154,7 +154,7 @@ def handleVoteIdeaLocked(*serve.Context c) ( ) def handleGetIdeaComments(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -165,7 +165,7 @@ def handleGetIdeaComments(*serve.Context c) ( ) def handleCreateIdeaComment(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -204,7 +204,7 @@ def handleCreateIdeaComment(*serve.Context c) ( ) def handleDeleteIdeaComment(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -228,7 +228,7 @@ def handleDeleteIdeaComment(*serve.Context c) ( ) def handleEditIdeaComment(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -247,7 +247,7 @@ def handleEditIdeaComment(*serve.Context c) ( ) def handleReactIdeaComment(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -256,7 +256,7 @@ def handleReactIdeaComment(*serve.Context c) ( ) def handleUpdateIdea(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if idea.len == 0 ( c.notFound("idea not found") return diff --git a/src/community/social.osl b/src/community/social.osl index 4b00137..44d55aa 100644 --- a/src/community/social.osl +++ b/src/community/social.osl @@ -221,7 +221,7 @@ def userPlaytimeLibrary(string name,*serve.Context c) array ( array library = [] for i savedProjects.len ( string projectId = savedProjects[i].toStr() - object project = (projectSearchDocs.findById(projectId) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) boolean libraryPublic = !hiddenProjects.contains(projectId) boolean include = libraryPublic and project.len > 0 and projectVisibility(project) == "public" if !include and project.len > 0 ( @@ -276,7 +276,7 @@ def handleGetUser(*serve.Context c) ( ) ) if !featuredIncluded ( - object featured = (projectSearchDocs.findById(featuredId) ?? {}) + object featured = (projectSearchDocs.findById(featuredId).unwrapOr(null) ?? {}) if featured.len > 0 and featured.shared == true and featured.ownerKey.toStr() == key and projectsVisibleTo([featured], c).len > 0 ( projects.append(featured) ) @@ -500,7 +500,7 @@ def handleGetUserProjects(*serve.Context c) ( if userIdForUsername(name) == "" ( discoverUserIdentity(name) ) - boolean includeUnshared = isViewerOwner(c, name) and c.queryBool("all", false) + boolean includeUnshared = isViewerOwner(c, name) and c.queryBool("all", false).unwrapOr(false) array projects = projectsVisibleTo(ownerIndexEntries(name, includeUnshared), c) number requestedLimit = c.queryInt("limit", 0) if requestedLimit > 0 ( @@ -722,7 +722,7 @@ def handleSetLibraryProjectVisibility(*serve.Context c) ( ) def activityProjectVisibility(string projectId) string ( - object project = (projectSearchDocs.findById(projectId) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) if project.len > 0 and projectIsViewable(project) ( return projectVisibility(project) ) @@ -777,7 +777,7 @@ def handleGetActivity(*serve.Context c) ( string author = normalizeUsername(review.author.toStr()) string projectId = review.projectId.toStr() if selectedUsers.contains(author) and activityProjectVisibility(projectId) == "public" ( - object project = (projectSearchDocs.findById(projectId) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) items.append({type: "review", actor: review.author, projectId: review.projectId, projectTitle: project.title, rating: review.rating, message: review.message, created: review.edited}) reviewItems += 1 ) diff --git a/src/community/space-comments.osl b/src/community/space-comments.osl index dbe4e53..0e339fe 100644 --- a/src/community/space-comments.osl +++ b/src/community/space-comments.osl @@ -1,5 +1,5 @@ def handleGetSpaceComments(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -10,7 +10,7 @@ def handleGetSpaceComments(*serve.Context c) ( ) def handleCreateSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -50,7 +50,7 @@ def handleCreateSpaceComment(*serve.Context c) ( ) def handleDeleteSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -74,7 +74,7 @@ def handleDeleteSpaceComment(*serve.Context c) ( ) def handleEditSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -93,7 +93,7 @@ def handleEditSpaceComment(*serve.Context c) ( ) def handlePinSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -117,7 +117,7 @@ def handlePinSpaceComment(*serve.Context c) ( ) def handleReactSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return diff --git a/src/community/space-memberships.osl b/src/community/space-memberships.osl index 7ea63a9..17ba901 100644 --- a/src/community/space-memberships.osl +++ b/src/community/space-memberships.osl @@ -51,7 +51,7 @@ def syncSpaceMemberships(object space) boolean ( array keys = spaceRelatedUserKeys(space) string signature = json.stringify(keys) string stateId = "space:" ++ spaceId - object state = (spaceMemberDocs.findById(stateId) ?? {}) + object state = (spaceMemberDocs.findById(stateId).unwrapOr(null) ?? {}) if state.len > 0 and state.signature.toStr() == signature ( return true ) @@ -87,7 +87,7 @@ def deleteSpaceMemberships(string spaceId) boolean ( def migrateSpaceMemberships() boolean ( string migrationId = "migration:space-members-v1" - if (spaceMemberDocs.findById(migrationId) ?? {}).len > 0 ( + if (spaceMemberDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( return true ) array previous = spaceMemberDocs.all() diff --git a/src/community/space-responses.osl b/src/community/space-responses.osl index d18f5c6..068f4ec 100644 --- a/src/community/space-responses.osl +++ b/src/community/space-responses.osl @@ -99,7 +99,7 @@ def spaceListResponse(object space,*serve.Context c) object ( number projectCount = 0 boolean canManage = canManageSpace(space, c) for i ids.len ( - object project = (projectSearchDocs.findById(ids[i].toStr()) ?? {}) + object project = (projectSearchDocs.findById(ids[i].toStr()).unwrapOr(null) ?? {}) boolean hidden = projectHiddenFrom(project, c) if project.len > 0 and !hidden and (project.shared == true or project.visibility.toStr() == "unlisted" or canManage) ( projectCount += 1 diff --git a/src/community/spaces.osl b/src/community/spaces.osl index 18864dd..9f579a8 100644 --- a/src/community/spaces.osl +++ b/src/community/spaces.osl @@ -90,7 +90,7 @@ def handleListSpaces(*serve.Context c) ( ) def handleGetSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -204,7 +204,7 @@ def handleCreateSpace(*serve.Context c) ( ) def handleUpdateSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -232,7 +232,7 @@ def handleUpdateSpace(*serve.Context c) ( return ) number nextOwnerLimit = mistwarpBenefitsForUserId(nextOwnerId).maxSpaces.toNum() - if !identityMatches((space.ownerId ?? "").toStr(), space.owner.toStr(), nextOwnerId, nextOwner) and spaceDocs.where("ownerId", "==", nextOwnerId).count() >= nextOwnerLimit ( + if !identityMatches((space.ownerId ?? "").toStr(), space.owner.toStr(), nextOwnerId, nextOwner) and spaceDocs.where("ownerId", "==", nextOwnerId).count().unwrap() >= nextOwnerLimit ( c.badRequest("the new owner has reached their space limit") return ) @@ -352,7 +352,7 @@ def handleUpdateSpace(*serve.Context c) ( ) def handleDeleteSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -372,7 +372,7 @@ def handleDeleteSpace(*serve.Context c) ( ) def handleSetSpaceThumbnail(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -391,7 +391,7 @@ def handleSetSpaceThumbnail(*serve.Context c) ( c.badRequest("thumbnail too large") return ) - if !fs.writeFileBytes(spaceThumbnailPath(space["_id"].toStr()), thumbnail.data) ( + if !fs.writeFileBytes(spaceThumbnailPath(space["_id"].toStr()), thumbnail.data).isOk() ( c.internalError("thumbnail save failed") return ) @@ -401,8 +401,8 @@ def handleSetSpaceThumbnail(*serve.Context c) ( ) def handleAddSpaceProject(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) - object project = (projectSearchDocs.findById(c.param("project")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(c.param("project")).unwrapOr(null) ?? {}) if space.len == 0 or project.len == 0 ( c.notFound("space or project not found") return @@ -445,12 +445,12 @@ def handleAddSpaceProject(*serve.Context c) ( ) def handleRemoveSpaceProject(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return ) - object project = (projectSearchDocs.findById(c.param("project")) ?? {}) + object project = (projectSearchDocs.findById(c.param("project")).unwrapOr(null) ?? {}) boolean allowed = canManageSpace(space, c) if project.len > 0 ( allowed = allowed or searchEntryOwnedByContext(project, c) @@ -477,7 +477,7 @@ def handleRemoveSpaceProject(*serve.Context c) ( ) def handleFollowSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -492,7 +492,7 @@ def handleFollowSpace(*serve.Context c) ( ) def handleUnfollowSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -513,7 +513,7 @@ def handleMySpaces(*serve.Context c) ( object seen = {} for i memberships.len ( object membership = memberships[i].assert(object) - object space = (spaceDocs.findById(membership.spaceId.toStr()) ?? {}) + object space = (spaceDocs.findById(membership.spaceId.toStr()).unwrapOr(null) ?? {}) if space.len > 0 ( seen[space["_id"].toStr()] = true stored.append(space) @@ -544,7 +544,7 @@ def handleMySpaces(*serve.Context c) ( ) def handleGetSpaceManagement(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -557,7 +557,7 @@ def handleGetSpaceManagement(*serve.Context c) ( ) def handleInviteSpaceCurator(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -572,7 +572,7 @@ def handleInviteSpaceCurator(*serve.Context c) ( c.badRequest("choose another user") return ) - object profile = (profileSearchDocs.findById(usernameKey) ?? {}) + object profile = (profileSearchDocs.findById(usernameKey).unwrapOr(null) ?? {}) if profile.len == 0 ( c.notFound("user not found") return @@ -599,7 +599,7 @@ def handleInviteSpaceCurator(*serve.Context c) ( ) def handleRespondSpaceCuratorInvite(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -640,7 +640,7 @@ def handleRespondSpaceCuratorInvite(*serve.Context c) ( ) def handleRemoveSpaceCurator(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -661,7 +661,7 @@ def handleRemoveSpaceCurator(*serve.Context c) ( ) def handleCancelSpaceCuratorInvite(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -698,7 +698,7 @@ def handleReactSpace(*serve.Context c) ( ) def handleReactSpaceLocked(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return diff --git a/src/config/config.osl b/src/config/config.osl index 39cea43..5884fe4 100644 --- a/src/config/config.osl +++ b/src/config/config.osl @@ -224,8 +224,8 @@ string localBlobsDir = "data/blobs/" *s3.Client r2Client = s3.new({ "endpoint": if r2Local then "http://127.0.0.1:9" else r2Endpoint, "bucket": r2Bucket, - "access_key_id": r2AccessKeyId, - "secret_access_key": r2SecretAccessKey, + "accessKeyId": r2AccessKeyId, + "secretAccessKey": r2SecretAccessKey, "region": "auto" }) diff --git a/src/core/database.osl b/src/core/database.osl index cb0e704..f427bf4 100644 --- a/src/core/database.osl +++ b/src/core/database.osl @@ -96,8 +96,8 @@ def openCollection(*db.DB database, string name) *db.Collection ( def putDocument(*db.Collection collection, string id, object value) boolean ( value["_id"] = id - if collection.exists({_id: id}) ( - return collection.replaceOne({_id: id}, value) == 1 + if collection.exists({_id: id}).unwrap() ( + return collection.replaceOne({_id: id}, value).unwrap() == 1 ) return collection.insertOne(value).isOk() ) @@ -166,7 +166,7 @@ def deleteProjectCommunityRecords(string projectId) boolean ( def syncSearchProject(object project) boolean ( object entry = indexEntryFromProject(project) if entry.remixRoot.toStr() == "" and entry.remixParent.toStr() != "" ( - object parent = (projectSearchDocs.findById(entry.remixParent.toStr()) ?? {}) + object parent = (projectSearchDocs.findById(entry.remixParent.toStr()).unwrapOr(null) ?? {}) if parent.len > 0 ( entry.remixRoot = parent.id if parent.contains("remixRoot") and parent.remixRoot.toStr() != "" ( @@ -201,7 +201,7 @@ def removeSearchProject(string id) boolean ( def migratePullCommentCounts() boolean ( string migrationId = "migration:pull-comment-count-v1" - if (diagnosticDocs.findById(migrationId) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( return true ) array pulls = pullDocs.all() @@ -218,7 +218,7 @@ def migratePullCommentCounts() boolean ( ) def initCommunityDatabase() boolean ( - if projectSearchDocs.count({}) == 0 ( + if projectSearchDocs.count({}).unwrap() == 0 ( array projectFiles = fs.readDir(projectsDir).unwrapOr([]) for i projectFiles.len ( string file = projectFiles[i].toStr() @@ -233,7 +233,7 @@ def initCommunityDatabase() boolean ( ) ) ) - if profileSearchDocs.count({}) == 0 ( + if profileSearchDocs.count({}).unwrap() == 0 ( array names = fs.readDir(usersDir).unwrapOr([]) for i names.len ( string file = names[i].toStr() @@ -308,7 +308,7 @@ def validPreviewKey(string projectId, string key) boolean ( if key == "" ( return false ) - object preview = previewDocs.findOne({projectId: projectId, key: key}) ?? {} + object preview = previewDocs.findOne({projectId: projectId, key: key}).unwrapOr(null) ?? {} if preview.len == 0 ( return false ) @@ -323,9 +323,9 @@ def projectPlaytimeRecord(string projectId, string username) object ( if identityKey == "" ( identityKey = normalizeUsername(username) ) - object entry = (playtimeDocs.findById(projectId ++ ":" ++ identityKey) ?? {}) + object entry = (playtimeDocs.findById(projectId ++ ":" ++ identityKey).unwrapOr(null) ?? {}) if entry.len == 0 and identityKey != normalizeUsername(username) ( - entry = (playtimeDocs.findById(projectId ++ ":" ++ normalizeUsername(username)) ?? {}) + entry = (playtimeDocs.findById(projectId ++ ":" ++ normalizeUsername(username)).unwrapOr(null) ?? {}) ) return entry ) diff --git a/src/core/utils.osl b/src/core/utils.osl index 732dc96..bb70620 100644 --- a/src/core/utils.osl +++ b/src/core/utils.osl @@ -85,7 +85,7 @@ def copyFileReplacing(string source, string target) boolean ( if !fs.isFile(source) or fs.isDir(target) ( return false ) - if fs.copy(source, target, {overwrite: true}) ( + if fs.copy(source, target, {overwrite: true}).isOk() ( return true ) void fs.remove(target, {force: true}) diff --git a/src/games/game-data.osl b/src/games/game-data.osl index ed9a397..adf1189 100644 --- a/src/games/game-data.osl +++ b/src/games/game-data.osl @@ -397,11 +397,11 @@ def deleteGameSavesLocked(string projectId, string userId) boolean ( boolean deleted = false if fs.exists(playPath) ( removedBytes += fs.size(playPath).unwrapOr(0) - deleted = fs.remove(playPath) or deleted + deleted = fs.remove(playPath).isOk() or deleted ) if fs.exists(testPath) ( removedBytes += fs.size(testPath).unwrapOr(0) - deleted = fs.remove(testPath) or deleted + deleted = fs.remove(testPath).isOk() or deleted ) if removedBytes > 0 ( number usedBytes = storedGameSaveBytes(userId) diff --git a/src/git/git-inspection.osl b/src/git/git-inspection.osl index 8e2f1e9..566f7b3 100644 --- a/src/git/git-inspection.osl +++ b/src/git/git-inspection.osl @@ -67,7 +67,7 @@ def cachedProjectWorkspacePath(object project) string ( void fs.remove(temporaryPath) return "" ) - if !fs.rename(temporaryPath, cachedPath) ( + if !fs.rename(temporaryPath, cachedPath).isOk() ( void fs.remove(temporaryPath) if !fs.exists(cachedPath) ( return "" @@ -184,7 +184,7 @@ def cachedWorkspaceGitInspectionJSON(object project, string workspacePath, strin string resultJson = if sha == "worktree" then gitinspection.InspectWorktree(workspacePath, projectGitHead(project), operation, requestedPath, allowedHeads) else gitinspection.Inspect(workspacePath, sha, operation, requestedPath, allowedHeads) if resultJson.toBytes().len <= 1048576 and gitinspection.InspectionError(resultJson) == "" ( string temporaryPath = cachePath ++ ".tmp." ++ randomString(8) - if !fs.writeFile(temporaryPath, resultJson) or !fs.rename(temporaryPath, cachePath) ( + if !fs.writeFile(temporaryPath, resultJson).isOk() or !fs.rename(temporaryPath, cachePath).isOk() ( void fs.remove(temporaryPath) ) ) @@ -255,7 +255,7 @@ def cachedRemixArchiveDivergence(object child, object parent) object ( raw = gitinspection.CompareDivergence(childPath, childHead, parentPath, parentHead) if raw.toBytes().len <= 65536 and gitinspection.InspectionError(raw) == "" ( string temporaryPath = cachePath ++ ".tmp." ++ randomString(8) - if !fs.writeFile(temporaryPath, raw) or !fs.rename(temporaryPath, cachePath) ( + if !fs.writeFile(temporaryPath, raw).isOk() or !fs.rename(temporaryPath, cachePath).isOk() ( void fs.remove(temporaryPath) ) ) @@ -441,8 +441,8 @@ def storeCommitSummaries(string cacheDir, string cacheName, object computed) ( defer sync.unlock(lockName) object cached = mergedCommitSummaryCache(readCommitSummaryCache(cachePath), computed) string temporaryPath = cachePath ++ ".tmp." ++ randomString(8) - if fs.writeFile(temporaryPath, json.stringify(cached)) ( - if !fs.rename(temporaryPath, cachePath) ( + if fs.writeFile(temporaryPath, json.stringify(cached)).isOk() ( + if !fs.rename(temporaryPath, cachePath).isOk() ( void fs.remove(temporaryPath) ) ) diff --git a/src/git/pulls.osl b/src/git/pulls.osl index f906d7e..5898df9 100644 --- a/src/git/pulls.osl +++ b/src/git/pulls.osl @@ -72,7 +72,7 @@ def livePullResponse(object pull, string baseCommit, string headCommit) object ( ) def pullDocument(string targetId, string index) object ( - return (pullDocs.findById(targetId ++ ":" ++ index) ?? {}) + return (pullDocs.findById(targetId ++ ":" ++ index).unwrapOr(null) ?? {}) ) def pullCommentKey(object pull) string ( diff --git a/src/history/history-migration.test.osl b/src/history/history-migration.test.osl index e4ad5bc..aecef56 100644 --- a/src/history/history-migration.test.osl +++ b/src/history/history-migration.test.osl @@ -72,7 +72,7 @@ def copyFileReplacing(string source, string target) boolean ( if !fs.isFile(source) or fs.isDir(target) ( return false ) - if fs.copy(source, target, {overwrite: true}) ( + if fs.copy(source, target, {overwrite: true}).isOk() ( return true ) void fs.remove(target, {force: true}) diff --git a/src/projects/extensions.osl b/src/projects/extensions.osl index 4545d17..2c00e0c 100644 --- a/src/projects/extensions.osl +++ b/src/projects/extensions.osl @@ -199,7 +199,7 @@ def readProjectExtensionUrls(*json.Stream stream) object ( ) def inspectProjectExtensionUrls(string jsonPath) object ( - *json.Stream stream = json.open(jsonPath, maxProjectJsonBytes) catch (err) ( + *json.Stream stream = json.open(jsonPath, {maxBytes: maxProjectJsonBytes}) catch (err) ( return {ok: false, error: "invalid extension URLs"} ) object inspected = readProjectExtensionUrls(stream) catch (err) ( @@ -330,7 +330,7 @@ def recordProjectExtensionLocked(object policy, string hash, string projectId, s sync.lock(lockName) defer sync.unlock(lockName) if !gallery and !fs.exists(extensionSourcePath(hash)) and sources.contains(extensionUrl) ( - if !fs.writeFile(extensionSourcePath(hash), sources[extensionUrl].toStr()) ( + if !fs.writeFile(extensionSourcePath(hash), sources[extensionUrl].toStr()).isOk() ( return false ) ) @@ -441,7 +441,7 @@ def inspectStoredProjectExtensionUrls(object project) object ( string workId = project.id.toStr() ++ "." ++ randomString(8) string gzipPath = tmpDir ++ workId ++ ".json.gz" string jsonPath = tmpDir ++ workId ++ ".json" - if !copyStoredProjectJsonToPath(project, gzipPath) or !zip.gunzip(gzipPath, jsonPath) ( + if !copyStoredProjectJsonToPath(project, gzipPath) or !zip.gunzip(gzipPath, jsonPath).isOk() ( void fs.remove(gzipPath) void fs.remove(jsonPath) return {ok: false, urls: []} @@ -790,7 +790,7 @@ def handleAdminIndexProjectExtensions(*serve.Context c) ( string workId = project.id.toStr() ++ "." ++ randomString(8) string gzipPath = tmpDir ++ workId ++ ".json.gz" string jsonPath = tmpDir ++ workId ++ ".json" - if !copyStoredProjectJsonToPath(project, gzipPath) or !zip.gunzip(gzipPath, jsonPath) ( + if !copyStoredProjectJsonToPath(project, gzipPath) or !zip.gunzip(gzipPath, jsonPath).isOk() ( void fs.remove(gzipPath) void fs.remove(jsonPath) c.internalError("could not inspect project") diff --git a/src/projects/project-read.osl b/src/projects/project-read.osl index 53e37d2..4fff1d5 100644 --- a/src/projects/project-read.osl +++ b/src/projects/project-read.osl @@ -16,7 +16,7 @@ def handleGetProject(*serve.Context c) ( object response = projectResponse(project, c) object jsonAccess = projectJsonAccess(project, c) if project.shared == true and project.contains("publicRelease") and project.publicRelease.toStr() != "" and response.ownerBanned != true and jsonAccess.allowed == true ( - object release = (releaseDocs.findById(project.publicRelease.toStr()) ?? {}) + object release = (releaseDocs.findById(project.publicRelease.toStr()).unwrapOr(null) ?? {}) if release.len > 0 and release.contains("jsonUrl") ( response.projectJsonUrl = keyedJsonUrl(release.jsonUrl.toStr(), jsonAccess) response.releaseVersion = release.version @@ -61,7 +61,7 @@ def handleGetProjectTrustedExtensions(*serve.Context c) ( ) array jsonUrls = [projectJsonBaseUrl(project)] if project.shared == true and (project.publicRelease ?? "").toStr() != "" ( - object release = (releaseDocs.findById(project.publicRelease.toStr()) ?? {}) + object release = (releaseDocs.findById(project.publicRelease.toStr()).unwrapOr(null) ?? {}) if (release.jsonUrl ?? "").toStr() != "" ( jsonUrls.append(release.jsonUrl.toStr()) ) diff --git a/src/projects/project-remix.osl b/src/projects/project-remix.osl index 11650a8..f6f9631 100644 --- a/src/projects/project-remix.osl +++ b/src/projects/project-remix.osl @@ -74,7 +74,7 @@ def handleGetRemixTree(*serve.Context c) ( array nodes = [] object seen = {} - object root = (projectSearchDocs.findById(rootId) ?? {}) + object root = (projectSearchDocs.findById(rootId).unwrapOr(null) ?? {}) if root.len > 0 ( nodes.append(root) seen[rootId] = true @@ -391,7 +391,7 @@ def createFork(PreparedFork prepared, ForkRequest request, ForkOutcome outcome) gitGraph: forkHistory.graph, collaborators: [] } - object parentEntry = (projectSearchDocs.findById(parentId) ?? {}) + object parentEntry = (projectSearchDocs.findById(parentId).unwrapOr(null) ?? {}) if parentEntry.len > 0 and parentEntry.contains("remixRoot") and parentEntry.remixRoot.toStr() != "" ( project.remixRoot = parentEntry.remixRoot ) diff --git a/src/projects/project-snapshots.osl b/src/projects/project-snapshots.osl index 4cb99ca..a4c7290 100644 --- a/src/projects/project-snapshots.osl +++ b/src/projects/project-snapshots.osl @@ -19,7 +19,7 @@ def stageProjectJson(object project, string gzipPath) boolean ( if !copyFileReplacing(gzipPath, tmpPath) ( return false ) - if !fs.rename(tmpPath, path) ( + if !fs.rename(tmpPath, path).isOk() ( void fs.remove(tmpPath) return false ) @@ -153,7 +153,7 @@ def flushProjectLocked(object project) ( string gzipPath = path if !projectJsonIsGzip(project) ( gzipPath = path ++ ".gz" - if !zip.gzip(path, gzipPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}) ( + if !zip.gzip(path, gzipPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}).isOk() ( return ) ) diff --git a/src/projects/project-upload-files.osl b/src/projects/project-upload-files.osl index e0a9ea0..d6cab9f 100644 --- a/src/projects/project-upload-files.osl +++ b/src/projects/project-upload-files.osl @@ -34,7 +34,7 @@ def scanProjectJsonEvents(*json.Stream stream) object ( ) def inspectProjectJson(string path) object ( - *json.Stream stream = json.open(path, maxProjectJsonBytes) + *json.Stream stream = json.open(path, {maxBytes: maxProjectJsonBytes}) object inspected = scanProjectJsonEvents(stream) catch (err) ( stream.close() return {ok: false} @@ -61,7 +61,7 @@ def uploadProjectFiles(object project, string extractDir, object benefits, numbe return {ok: false, error: "invalid project.json", status: 400} ) string gzipPath = jsonPath ++ ".gz" - if !zip.gzip(jsonPath, gzipPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}) ( + if !zip.gzip(jsonPath, gzipPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}).isOk() ( return {ok: false, error: "compressed project data exceeds the 20 MB limit", code: "project_too_large", status: 413} ) diff --git a/src/projects/project-upload-history.osl b/src/projects/project-upload-history.osl index cdfaf20..2f37787 100644 --- a/src/projects/project-upload-history.osl +++ b/src/projects/project-upload-history.osl @@ -59,7 +59,7 @@ def unchangedVersionCheck(object project, UploadRequest request, UploadHistory h ) string compareBasePath = cachedProjectWorkspacePath(project) string compareIncomingPath = tmpDir ++ archive.workId ++ ".compare-incoming.mwp" - boolean compareReady = compareBasePath != "" and fs.writeFileBytes(compareIncomingPath, history.workspace) + boolean compareReady = compareBasePath != "" and fs.writeFileBytes(compareIncomingPath, history.workspace).isOk() string comparisonJson = "" if compareReady ( comparisonJson = gitinspection.CommitTreesDiffer(compareBasePath, history.currentHead, compareIncomingPath, incomingHead) @@ -152,7 +152,7 @@ def createMergeCommit(*serve.Context c, object project, UploadRequest request, U string mergeDeltaPath = tmpDir ++ archive.workId ++ ".merge-delta.mwp" boolean mergeReady = copyProjectWorkspaceToPath(project, mergeTargetPath) mergeReady = mergeReady and copyProjectWorkspaceToPath(mergeSource, mergeSourcePath) - mergeReady = mergeReady and fs.writeFileBytes(mergeTreePath, history.mergeTree) + mergeReady = mergeReady and fs.writeFileBytes(mergeTreePath, history.mergeTree).isOk() HistoryIdentity identity = historyIdentity(project) string mergeBranch = if branchMerge then request.mergeTargetBranch else identity.branch number mergeTimestamp = timestamp @@ -253,7 +253,7 @@ def materializeWorktreeAssets(object project, byte[] body, string extractDir, bo string incomingPath = workId ++ ".refs.mwp" string outputPath = workId ++ ".materialized.mwp" string fetchDir = workId ++ ".assets" - if !fs.writeFileBytes(incomingPath, body) ( + if !fs.writeFileBytes(incomingPath, body).isOk() ( return {ok: false} ) string basePath = "" @@ -305,7 +305,7 @@ def validateUploadedHistoryMode(object project, byte[] body, string metadata, st return {ok: false, error: "stored history unavailable; retry later"} ) ) - if !fs.writeFileBytes(incomingPath, body) ( + if !fs.writeFileBytes(incomingPath, body).isOk() ( return {ok: false, error: "could not stage history"} ) string forkBase = (project.remixBaseCommit ?? "").toStr() diff --git a/src/projects/project-upload-receive.osl b/src/projects/project-upload-receive.osl index df2f48c..a914b59 100644 --- a/src/projects/project-upload-receive.osl +++ b/src/projects/project-upload-receive.osl @@ -96,7 +96,7 @@ def unpackProjectArchive(object project, object benefits, UploadArchive archive) archive.workId = project.id.toStr() ++ "." ++ randomString(8) archive.zipPath = tmpDir ++ archive.workId ++ ".sb3" archive.extractDir = tmpDir ++ archive.workId - if !fs.writeFileBytes(archive.zipPath, archive.data) ( + if !fs.writeFileBytes(archive.zipPath, archive.data).isOk() ( return refuse(500, "failed to stage project upload") ) archive.expandedLimit = maxProjectJsonBytes + benefits.maxProjectAssetsBytes.toNum() @@ -104,7 +104,7 @@ def unpackProjectArchive(object project, object benefits, UploadArchive archive) void fs.remove(archive.zipPath) return refuse(400, "invalid or unsafe sb3 file") ) - if !zip.decompress(archive.zipPath, archive.extractDir, {maxBytes: archive.expandedLimit, maxFiles: maxAssetCount + 1}) ( + if !zip.decompress(archive.zipPath, archive.extractDir, {maxBytes: archive.expandedLimit, maxFiles: maxAssetCount + 1}).isOk() ( archive.discard() return refuse(400, "invalid sb3 file") ) diff --git a/src/projects/project-upload.osl b/src/projects/project-upload.osl index 1fff723..32ab41a 100644 --- a/src/projects/project-upload.osl +++ b/src/projects/project-upload.osl @@ -173,7 +173,7 @@ def handleSetThumbnail(*serve.Context c) ( c.badRequest("thumbnail too large") return ) - if !fs.writeFileBytes(thumbnailPath(project.id.toStr()), thumb.data) ( + if !fs.writeFileBytes(thumbnailPath(project.id.toStr()), thumb.data).isOk() ( c.internalError("thumbnail save failed") return ) diff --git a/src/projects/upload-parts.osl b/src/projects/upload-parts.osl index 7514474..c0f1f88 100644 --- a/src/projects/upload-parts.osl +++ b/src/projects/upload-parts.osl @@ -170,7 +170,7 @@ def handleStageProjectUploadPart(*serve.Context c) ( return ) string token = randomString(32) - if !fs.writeFileBytes(stagedUploadPartDataPath(token), file.data) or !writeFile(stagedUploadPartMetaPath(token), { + if !fs.writeFileBytes(stagedUploadPartDataPath(token), file.data).isOk() or !writeFile(stagedUploadPartMetaPath(token), { projectId: project.id, kind: kind, userId: contextString(c, "userId"), @@ -313,7 +313,7 @@ def handleUploadProjectPartChunk(*serve.Context c) ( c.badRequest("upload exceeds its declared size") return ) - if !fs.writeFileBytes(uploadPartChunkPath(token, index), chunk.data) ( + if !fs.writeFileBytes(uploadPartChunkPath(token, index), chunk.data).isOk() ( c.internalError("could not store upload chunk") return ) diff --git a/src/rotur/rotur-app.osl b/src/rotur/rotur-app.osl index 53b81f7..c31e9de 100644 --- a/src/rotur/rotur-app.osl +++ b/src/rotur/rotur-app.osl @@ -24,7 +24,7 @@ def roturApp(string method, string path, object body) object ( if !roturAppReady() ( return {ok: false, status: 0, data: {}} ) - object options = {timeout: 10, headers: { + object options = {timeout: 10000, headers: { "Authorization": "Basic " ++ btoa(roturClientId ++ ":" ++ roturClientSecret), "Content-Type": "application/json" }} diff --git a/src/storage/r2-snapshot-serving.test.osl b/src/storage/r2-snapshot-serving.test.osl index cc14e0b..95c178f 100644 --- a/src/storage/r2-snapshot-serving.test.osl +++ b/src/storage/r2-snapshot-serving.test.osl @@ -33,7 +33,7 @@ def runStubServer() ( stubApp.run(":18331") ) -*s3.Client r2Client = s3.new({endpoint: "http://127.0.0.1:18331", bucket: "test", access_key_id: "test", secret_access_key: "test"}) +*s3.Client r2Client = s3.new({endpoint: "http://127.0.0.1:18331", bucket: "test", accessKeyId: "test", secretAccessKey: "test"}) def isSafeBlobKey(string key) boolean ( return key != "" and !key.contains("..") diff --git a/src/storage/r2-upload-queue.osl b/src/storage/r2-upload-queue.osl index f73bdbe..06effb7 100644 --- a/src/storage/r2-upload-queue.osl +++ b/src/storage/r2-upload-queue.osl @@ -165,7 +165,7 @@ def flushR2UploadQueue() ( ) if uploaded ( item.uploaded = true - removed = !fs.exists(path) or !r2UploadReady(item, activity, now) or fs.remove(path) + removed = !fs.exists(path) or !r2UploadReady(item, activity, now) or fs.remove(path).isOk() ) ) if !removed ( diff --git a/src/storage/r2-upload-queue.test.osl b/src/storage/r2-upload-queue.test.osl index c98c25c..5677045 100644 --- a/src/storage/r2-upload-queue.test.osl +++ b/src/storage/r2-upload-queue.test.osl @@ -167,7 +167,7 @@ testing.assert(puts.len == 7 and fs.exists(localBlobPath("assets/busy.svg")), "b void fs.writeFile(r2UploadQueueFile, "invalid json") testing.assert(!stageR2Blob("assets/retry.svg", "retry", "image/svg+xml", ""), "queue read errors fail staging safely") flushR2UploadQueue() -testing.assert(fs.readFile(r2UploadQueueFile) == "invalid json", "read failure never overwrites a queue") +testing.assert(fs.readFile(r2UploadQueueFile).unwrap() == "invalid json", "read failure never overwrites a queue") writeFile(r2UploadQueueFile, {items: [{key: "../unsafe"}]}) flushR2UploadQueue() testing.assert(loadR2UploadQueue().len == 0, "invalid keys are dropped") diff --git a/src/storage/r2.osl b/src/storage/r2.osl index fca1f75..f751c19 100644 --- a/src/storage/r2.osl +++ b/src/storage/r2.osl @@ -79,7 +79,7 @@ def handleGetThumbnail(*serve.Context c) ( ) def thumbnailAccess(string id, boolean hasKey) object ( - object entry = (projectSearchDocs.findById(id) ?? {}) + object entry = (projectSearchDocs.findById(id).unwrapOr(null) ?? {}) if entry.len > 0 and projectOwnerBanned(entry) ( return {found: true, ownerBanned: true, isPublic: false, viewKey: ""} ) @@ -341,7 +341,7 @@ def r2PutEncoded(string key, BlobBody body, string contentType, string contentEn return fs.writeFileBytes(path, body).isOk() ) string uploadType = if contentType == "" then "application/octet-stream" else contentType - boolean stored = key != "" and r2Client.upload(key, body, {contentType: uploadType, contentEncoding: contentEncoding}) + boolean stored = key != "" and r2Client.upload(key, body, {contentType: uploadType, contentEncoding: contentEncoding}).isOk() if stored ( recordR2Stored({key: key, type: r2ObjectType(key), size: body.len}) ) @@ -470,7 +470,7 @@ def r2Remove(string key) boolean ( ) if removed ( string path = localBlobPath(key) - removed = !fs.exists(path) or fs.remove(path) + removed = !fs.exists(path) or fs.remove(path).isOk() ) return removed ) @@ -549,7 +549,7 @@ def copyStoredProjectJsonToPath(object project, string outputPath) boolean ( return fs.writeFileBytes(outputPath, fetched.body).isOk() ) string plainPath = outputPath ++ ".plain" - if !fs.writeFileBytes(plainPath, fetched.body) ( + if !fs.writeFileBytes(plainPath, fetched.body).isOk() ( return false ) boolean compressed = zip.gzip(plainPath, outputPath, {maxInputBytes: maxProjectJsonBytes, maxBytes: maxStoredProjectJsonBytes}).isOk() diff --git a/src/storage/storage-ledger.osl b/src/storage/storage-ledger.osl index 159b8d0..497f2f2 100644 --- a/src/storage/storage-ledger.osl +++ b/src/storage/storage-ledger.osl @@ -73,7 +73,7 @@ def ledgerCall(string method, string path, object body) object ( if !ledgerReady() ( return {status: 0, body: {}} ) - object options = {timeout: 10, headers: { + object options = {timeout: 10000, headers: { "Content-Type": "application/json", "X-Rotur-Service-Secret": ledgerSecret.strip(), "X-Rotur-App": "mistwarp" diff --git a/src/storage/storage-usage.osl b/src/storage/storage-usage.osl index 5368252..d245065 100644 --- a/src/storage/storage-usage.osl +++ b/src/storage/storage-usage.osl @@ -85,7 +85,7 @@ def storageInventory() object ( def backfillProjectHistoryBytes() ( string migrationId = "migration:project-history-bytes-v1" - if (diagnosticDocs.findById(migrationId) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( return ) object listing = storageInventory() @@ -119,7 +119,7 @@ def backfillProjectHistoryBytes() ( def backfillReleaseJsonBytes() boolean ( string migrationId = "migration:release-json-bytes-v1" - if (diagnosticDocs.findById(migrationId) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( return true ) object listing = storageInventory() diff --git a/src/storage/storage.osl b/src/storage/storage.osl index 2009dd6..23e104e 100644 --- a/src/storage/storage.osl +++ b/src/storage/storage.osl @@ -26,28 +26,28 @@ export { def ensureDirectories() boolean ( boolean res = fs.mkdir(projectsDir, {recursive: true}).isOk() - res = res and fs.mkdir(usersDir, {recursive: true}) - res = res and fs.mkdir(sessionsDir, {recursive: true}) - res = res and fs.mkdir(commentsDir, {recursive: true}) - res = res and fs.mkdir(reportsDir, {recursive: true}) - res = res and fs.mkdir(notificationsDir, {recursive: true}) - res = res and fs.mkdir(activityDir, {recursive: true}) - res = res and fs.mkdir(userSettingsDir, {recursive: true}) - res = res and fs.mkdir(tmpDir, {recursive: true}) - res = res and fs.mkdir(stagingDir, {recursive: true}) - res = res and fs.mkdir(thumbnailsDir, {recursive: true}) - res = res and fs.mkdir(cardsDir, {recursive: true}) - res = res and fs.mkdir(quotaDir, {recursive: true}) - res = res and fs.mkdir(agreementAcceptDir, {recursive: true}) - res = res and fs.mkdir(extensionsDir, {recursive: true}) - res = res and fs.mkdir(releasesDir, {recursive: true}) - res = res and fs.mkdir(safetyDir, {recursive: true}) - res = res and fs.mkdir(trashDir, {recursive: true}) - res = res and fs.mkdir(gameSavesDir, {recursive: true}) - res = res and fs.mkdir(gameSaveUsageDir, {recursive: true}) - res = res and fs.mkdir(gameEntitlementsDir, {recursive: true}) - res = res and fs.mkdir(gameInventoryDir, {recursive: true}) - res = res and fs.mkdir(backpackDir, {recursive: true}) + res = res and fs.mkdir(usersDir, {recursive: true}).isOk() + res = res and fs.mkdir(sessionsDir, {recursive: true}).isOk() + res = res and fs.mkdir(commentsDir, {recursive: true}).isOk() + res = res and fs.mkdir(reportsDir, {recursive: true}).isOk() + res = res and fs.mkdir(notificationsDir, {recursive: true}).isOk() + res = res and fs.mkdir(activityDir, {recursive: true}).isOk() + res = res and fs.mkdir(userSettingsDir, {recursive: true}).isOk() + res = res and fs.mkdir(tmpDir, {recursive: true}).isOk() + res = res and fs.mkdir(stagingDir, {recursive: true}).isOk() + res = res and fs.mkdir(thumbnailsDir, {recursive: true}).isOk() + res = res and fs.mkdir(cardsDir, {recursive: true}).isOk() + res = res and fs.mkdir(quotaDir, {recursive: true}).isOk() + res = res and fs.mkdir(agreementAcceptDir, {recursive: true}).isOk() + res = res and fs.mkdir(extensionsDir, {recursive: true}).isOk() + res = res and fs.mkdir(releasesDir, {recursive: true}).isOk() + res = res and fs.mkdir(safetyDir, {recursive: true}).isOk() + res = res and fs.mkdir(trashDir, {recursive: true}).isOk() + res = res and fs.mkdir(gameSavesDir, {recursive: true}).isOk() + res = res and fs.mkdir(gameSaveUsageDir, {recursive: true}).isOk() + res = res and fs.mkdir(gameEntitlementsDir, {recursive: true}).isOk() + res = res and fs.mkdir(gameInventoryDir, {recursive: true}).isOk() + res = res and fs.mkdir(backpackDir, {recursive: true}).isOk() return res ) @@ -112,10 +112,10 @@ def readFile(string path) object ( def writeFile(string path, object data) boolean ( string tmpPath = path ++ ".tmp." ++ randomString(8) - if !fs.writeFile(tmpPath, json.stringify(data)) ( + if !fs.writeFile(tmpPath, json.stringify(data)).isOk() ( return false ) - if !fs.rename(tmpPath, path) ( + if !fs.rename(tmpPath, path).isOk() ( void fs.remove(tmpPath) return false ) @@ -402,7 +402,7 @@ def saveComments(string key, array comments) boolean ( ) string path = commentsDir ++ key ++ ".jsonl" string tmpPath = path ++ ".tmp." ++ randomString(8) - if !fs.writeFile(tmpPath, out) ( + if !fs.writeFile(tmpPath, out).isOk() ( return false ) boolean ok = fs.rename(tmpPath, path).isOk() diff --git a/src/storage/thumbnail-access.osl b/src/storage/thumbnail-access.osl index 39ce02d..aa2d06f 100644 --- a/src/storage/thumbnail-access.osl +++ b/src/storage/thumbnail-access.osl @@ -9,7 +9,7 @@ def loadThumbnailSecret(string path) string ( return stored ) string secret = crypto.randomString(32) - if !fs.writeFile(path, secret) ( + if !fs.writeFile(path, secret).isOk() ( log "WARNING: could not save " ++ path ++ "; private thumbnail links will change on restart" ) return secret From 979f0a4441a0042bb17d6c6f5dcaba53ed09f2ba Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 28 Nov 2026 01:32:52 +0000 Subject: [PATCH 3/5] Keep OSL 6.1 failure handling for db reads and the all query flag A failed findById or findOne read throws again instead of reading as a missing document, ?all= with a value that isn't a boolean answers 400 again, and the privacy test checks that the hidden list is an array. --- src/admin/admin-users.osl | 2 +- src/admin/errors.osl | 4 +-- src/admin/errors.test.osl | 14 ++++----- src/admin/funnel-events.osl | 2 +- src/admin/project-moderation.osl | 2 +- src/auth/privacy-policy.test.osl | 2 +- src/classroom/classroom-billing.osl | 12 ++++---- src/classroom/classroom-groups.osl | 8 +++--- src/classroom/classroom-legal.osl | 4 +-- src/classroom/classroom-present.osl | 2 +- src/classroom/classroom-release.osl | 6 ++-- src/classroom/classroom-schools.osl | 6 ++-- src/classroom/classroom-switch.test.osl | 2 +- src/classroom/classrooms.osl | 26 ++++++++--------- src/community/challenges.osl | 24 ++++++++-------- src/community/comments.osl | 2 +- src/community/community-user-records.osl | 4 +-- src/community/development.osl | 4 +-- src/community/like-milestones.osl | 2 +- src/community/like-milestones.test.osl | 2 +- src/community/news.osl | 2 +- src/community/playtime-diagnostics.osl | 8 +++--- src/community/project-feedback.osl | 4 +-- src/community/releases.osl | 4 +-- src/community/remote-milestones.osl | 2 +- src/community/roadmap.osl | 14 ++++----- src/community/social.osl | 10 +++---- src/community/space-comments.osl | 12 ++++---- src/community/space-memberships.osl | 4 +-- src/community/space-responses.osl | 2 +- src/community/spaces.osl | 36 ++++++++++++------------ src/core/database.osl | 10 +++---- src/git/pulls.osl | 2 +- src/projects/project-read.osl | 4 +-- src/projects/project-remix.osl | 4 +-- src/storage/r2.osl | 2 +- src/storage/storage-usage.osl | 4 +-- 37 files changed, 127 insertions(+), 127 deletions(-) diff --git a/src/admin/admin-users.osl b/src/admin/admin-users.osl index f78aa86..52cc905 100644 --- a/src/admin/admin-users.osl +++ b/src/admin/admin-users.osl @@ -111,7 +111,7 @@ def unindexComment(string key, string cid) ( def migrateCommentIndex() boolean ( string migrationId = "migration:comment-index-v1" - if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrap() ?? {}).len > 0 ( return true ) array files = fs.readDir(commentsDir).unwrapOr([]) diff --git a/src/admin/errors.osl b/src/admin/errors.osl index 1736602..4cca3be 100644 --- a/src/admin/errors.osl +++ b/src/admin/errors.osl @@ -336,7 +336,7 @@ def handleAdminResolveSiteError(*serve.Context c) ( def resolveSiteErrorLocked(*serve.Context c, string id, boolean resolved) object ( sync.lock("site-errors") defer sync.unlock("site-errors") - object entry = (errorDocs.findById(id).unwrapOr(null) ?? {}) + object entry = (errorDocs.findById(id).unwrap() ?? {}) if entry.len == 0 ( c.notFound("error not found") return {found: false} @@ -369,7 +369,7 @@ def handleAdminDeleteSiteError(*serve.Context c) ( c.badRequest("error id is required") return ) - if (errorDocs.findById(id).unwrapOr(null) ?? {}).len == 0 ( + if (errorDocs.findById(id).unwrap() ?? {}).len == 0 ( c.notFound("error not found") return ) diff --git a/src/admin/errors.test.osl b/src/admin/errors.test.osl index 2541be0..82da0b8 100644 --- a/src/admin/errors.test.osl +++ b/src/admin/errors.test.osl @@ -76,7 +76,7 @@ testing.assert(scrubbed.resolved == true and scrubbed.kind == "react" and scrubb errorDocs.insertOne({_id: "legacy", message: "m", url: "https://mistwarp.org/users/mist", username: "mist", userAgent: "x", projectId: "p1", created: timestamp, resolved: false}) pruneSiteErrors() -object legacy = errorDocs.findById("legacy").unwrapOr(null) ?? {} +object legacy = errorDocs.findById("legacy").unwrap() ?? {} testing.assert(legacy.len > 0 and !legacy.contains("username") and legacy.url == "https://mistwarp.org/users/:id", "the sweep scrubs reports stored before this change") void deleteAllSiteErrors() @@ -93,9 +93,9 @@ errorDocs.insertOne({_id: "old", resolved: false, created: now - (8 * 86400000)} errorDocs.insertOne({_id: "edge", resolved: true, created: now - (6 * 86400000)}) errorDocs.insertOne({_id: "new", resolved: false, created: now}) sweepSiteErrors() -testing.assert((errorDocs.findById("old").unwrapOr(null) ?? {}).len == 0, "the sweep deletes reports older than 7 days, resolved or not") -testing.assert((errorDocs.findById("edge").unwrapOr(null) ?? {}).len > 0, "the sweep keeps reports younger than 7 days") -testing.assert((errorDocs.findById("new").unwrapOr(null) ?? {}).len > 0, "the sweep keeps new reports") +testing.assert((errorDocs.findById("old").unwrap() ?? {}).len == 0, "the sweep deletes reports older than 7 days, resolved or not") +testing.assert((errorDocs.findById("edge").unwrap() ?? {}).len > 0, "the sweep keeps reports younger than 7 days") +testing.assert((errorDocs.findById("new").unwrap() ?? {}).len > 0, "the sweep keeps new reports") testing.assert(deleteAllSiteErrors() == 2, "only the expired report was swept") for i 1005 ( @@ -104,9 +104,9 @@ for i 1005 ( errorDocs.insertOne({_id: "stale", resolved: false, created: now - (200 * 86400000)}) pruneSiteErrors() testing.assert(errorDocs.count({}).unwrap() == 1000, "pruning keeps the newest 1000 reports") -testing.assert((errorDocs.findById("stale").unwrapOr(null) ?? {}).len == 0, "pruning drops expired reports too") -testing.assert((errorDocs.findById("c1").unwrapOr(null) ?? {}).len == 0, "pruning drops the oldest reports beyond the cap") -testing.assert((errorDocs.findById("c1005").unwrapOr(null) ?? {}).len > 0, "pruning keeps the newest report") +testing.assert((errorDocs.findById("stale").unwrap() ?? {}).len == 0, "pruning drops expired reports too") +testing.assert((errorDocs.findById("c1").unwrap() ?? {}).len == 0, "pruning drops the oldest reports beyond the cap") +testing.assert((errorDocs.findById("c1005").unwrap() ?? {}).len > 0, "pruning keeps the newest report") void deleteAllSiteErrors() testing.assert(sweepSiteErrors(), "a sweep that works reports success") testDb.close() diff --git a/src/admin/funnel-events.osl b/src/admin/funnel-events.osl index 2e92e1d..11986f1 100644 --- a/src/admin/funnel-events.osl +++ b/src/admin/funnel-events.osl @@ -4,7 +4,7 @@ def recordFunnelEvent(string key, number now) ( string id = "funnel:" ++ funnelDayKey(now) sync.lock("funnel-events") defer sync.unlock("funnel-events") - object doc = funnelDocs.findById(id).unwrapOr(null) ?? {} + object doc = funnelDocs.findById(id).unwrap() ?? {} object counts = {} if doc.contains("counts") and doc.counts != null ( counts = doc.counts.assert(object) diff --git a/src/admin/project-moderation.osl b/src/admin/project-moderation.osl index 4f2145a..d5b4873 100644 --- a/src/admin/project-moderation.osl +++ b/src/admin/project-moderation.osl @@ -226,7 +226,7 @@ def handleListShadowBans(*serve.Context c) ( for i projectIds.len ( string id = projectIds[i].toStr() object entry = projects[id].assertElse(object, {}) - object indexed = (projectSearchDocs.findById(id).unwrapOr(null) ?? {}) + object indexed = (projectSearchDocs.findById(id).unwrap() ?? {}) projectRows.append({ id: id, title: if indexed.len > 0 then indexed.title else entry.title ?? "", diff --git a/src/auth/privacy-policy.test.osl b/src/auth/privacy-policy.test.osl index 7310795..db2dbec 100644 --- a/src/auth/privacy-policy.test.osl +++ b/src/auth/privacy-policy.test.osl @@ -45,7 +45,7 @@ testing.assert(privacyAdult.minor == false, "adult activity privacy is not a min testing.assert(privacyAdult.hiddenLibrary.assert(array).contains("p9"), "hidden library items are carried over") object privacyMinor = activityPrivacy({username: "sam", minor: true}) testing.assert(privacyMinor.showActivity == false, "minor activity privacy hides activity by default") -testing.assert(privacyMinor.hiddenLibrary.len == 0, "a missing hidden list is empty") +testing.assert(privacyMinor.hiddenLibrary.assert(array).len == 0, "a missing hidden list is empty") object visibilities = {p1: "public", p2: "unlisted", p3: "private", p9: "public"} object openPrivacy = {showActivity: true, minor: false, hiddenLibrary: ["p9"]} diff --git a/src/classroom/classroom-billing.osl b/src/classroom/classroom-billing.osl index afa87aa..b134c9b 100644 --- a/src/classroom/classroom-billing.osl +++ b/src/classroom/classroom-billing.osl @@ -28,7 +28,7 @@ def stripeRequest(string path, array fields) object ( ) def classroomBillingInfo(string userId) object ( - object stored = (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}) + object stored = (classroomPlanDocs.findById(userId).unwrap() ?? {}) boolean schoolManaged = schoolForTeacher(userId).len > 0 return { available: stripeBillingConfigured() and !schoolManaged, @@ -62,7 +62,7 @@ def startClassroomTrialLocked(*serve.Context c, string userId) boolean ( string lockName = "classroom-plan-" ++ userId sync.lock(lockName) defer sync.unlock(lockName) - object stored = (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}) + object stored = (classroomPlanDocs.findById(userId).unwrap() ?? {}) if !classroomTrialAvailable(stored, false, timestamp) ( c.json(409, {ok: false, code: "trial_unavailable", error: "The free trial is for teachers who have not had a Classroom plan before."}) return false @@ -85,7 +85,7 @@ def handleClassroomCheckout(*serve.Context c) ( return ) string userId = contextString(c, "userId") - object stored = (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}) + object stored = (classroomPlanDocs.findById(userId).unwrap() ?? {}) if classroomSubscriptionActive((stored.stripeStatus ?? "").toStr()) ( c.json(409, {ok: false, code: "already_subscribed", error: "You already have a Classroom subscription. Manage it from billing."}) return @@ -128,7 +128,7 @@ def handleClassroomBillingPortal(*serve.Context c) ( c.json(503, {ok: false, code: "billing_unavailable", error: "Online payment is not set up yet. Contact MistWarp support to change your plan."}) return ) - object stored = (classroomPlanDocs.findById(contextString(c, "userId")).unwrapOr(null) ?? {}) + object stored = (classroomPlanDocs.findById(contextString(c, "userId")).unwrap() ?? {}) string customerId = (stored.stripeCustomerId ?? "").toStr() if customerId == "" ( c.json(404, {ok: false, code: "no_billing_account", error: "You have not bought a plan online yet."}) @@ -146,7 +146,7 @@ def storeStripePlan(string userId, object update, number eventCreated) ( string lockName = "classroom-plan-" ++ userId sync.lock(lockName) defer sync.unlock(lockName) - object stored = (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}) + object stored = (classroomPlanDocs.findById(userId).unwrap() ?? {}) if stored.len == 0 ( stored = {_id: userId} ) @@ -168,7 +168,7 @@ def applyStripeSubscription(object subscription, number eventCreated, boolean de return ) string subscriptionId = (subscription.id ?? "").toStr() - if !stripeEventMayChangePlan((classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}), subscriptionId) ( + if !stripeEventMayChangePlan((classroomPlanDocs.findById(userId).unwrap() ?? {}), subscriptionId) ( return ) object plan = classroomPlanFromSubscription(subscription, [stripeSeatPackPrice, stripeSeatPackPriceYearly]) diff --git a/src/classroom/classroom-groups.osl b/src/classroom/classroom-groups.osl index 86761ae..2245f00 100644 --- a/src/classroom/classroom-groups.osl +++ b/src/classroom/classroom-groups.osl @@ -48,7 +48,7 @@ def groupForSubmission(object submission) object ( if groupId == "" ( return {} ) - object group = (classroomGroupDocs.findById(groupId).unwrapOr(null) ?? {}) + object group = (classroomGroupDocs.findById(groupId).unwrap() ?? {}) if group.len == 0 ( return {} ) @@ -103,14 +103,14 @@ def handleCreateClassGroup(*serve.Context c) ( object assignment = {} string assignmentId = (body.assignmentId ?? "").toStr() if assignmentId != "" ( - assignment = (assignmentDocs.findById(assignmentId).unwrapOr(null) ?? {}) + assignment = (assignmentDocs.findById(assignmentId).unwrap() ?? {}) if assignment.len == 0 or assignment.classId.toStr() != classId ( c.badRequest("choose an assignment from this class") return ) for i students.len ( object student = students[i].assert(object) - if (submissionDocs.findById(assignmentId ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}).len > 0 ( + if (submissionDocs.findById(assignmentId ++ ":" ++ student["_id"].toStr()).unwrap() ?? {}).len > 0 ( c.json(409, {ok: false, code: "already_started", error: student.displayName.toStr() ++ " has already started this assignment on their own."}) return ) @@ -184,7 +184,7 @@ def handleDeleteClassGroup(*serve.Context c) ( if classDoc.len == 0 ( return ) - object group = (classroomGroupDocs.findById(c.param("gid")).unwrapOr(null) ?? {}) + object group = (classroomGroupDocs.findById(c.param("gid")).unwrap() ?? {}) if group.len == 0 or group.classId.toStr() != classDoc["_id"].toStr() ( c.notFound("group not found") return diff --git a/src/classroom/classroom-legal.osl b/src/classroom/classroom-legal.osl index e57cc64..2fcebe2 100644 --- a/src/classroom/classroom-legal.osl +++ b/src/classroom/classroom-legal.osl @@ -3,7 +3,7 @@ export { } def classroomTermsRecord(string userId) object ( - return (classroomTermsDocs.findById(userId).unwrapOr(null) ?? {}) + return (classroomTermsDocs.findById(userId).unwrap() ?? {}) ) def classroomTermsStatus(string userId) object ( @@ -229,7 +229,7 @@ def handleAdminPurgeClassroom(*serve.Context c) ( string target = "" string schoolId = (body.schoolId ?? "").toStr() if schoolId != "" ( - object school = (schoolDocs.findById(schoolId).unwrapOr(null) ?? {}) + object school = (schoolDocs.findById(schoolId).unwrap() ?? {}) if school.len == 0 ( c.badRequest("school not found") return diff --git a/src/classroom/classroom-present.osl b/src/classroom/classroom-present.osl index ae4b627..2cb0f29 100644 --- a/src/classroom/classroom-present.osl +++ b/src/classroom/classroom-present.osl @@ -5,7 +5,7 @@ export { number classroomPresentationLifetimeMs = 14400000 def activePresentationForProject(string projectId) object ( - object presentation = (classroomPresentationDocs.findById(projectId).unwrapOr(null) ?? {}) + object presentation = (classroomPresentationDocs.findById(projectId).unwrap() ?? {}) if presentation.len == 0 or (presentation.expiresAt ?? 0).toNum() <= timestamp ( return {} ) diff --git a/src/classroom/classroom-release.osl b/src/classroom/classroom-release.osl index c7a1076..9f74fbe 100644 --- a/src/classroom/classroom-release.osl +++ b/src/classroom/classroom-release.osl @@ -6,7 +6,7 @@ def loadClassroomClaim(string code) object ( if code == "" ( return {} ) - return (classroomClaimDocs.findById(code).unwrapOr(null) ?? {}) + return (classroomClaimDocs.findById(code).unwrap() ?? {}) ) def claimIsUsable(object claim, number now) boolean ( @@ -46,7 +46,7 @@ def handleReleaseStudent(*serve.Context c) ( string code = "" for _ 20 ( string candidate = randomFromAlphabet(classCodeAlphabet, 10) - if code == "" and (classroomClaimDocs.findById(candidate).unwrapOr(null) ?? {}).len == 0 ( + if code == "" and (classroomClaimDocs.findById(candidate).unwrap() ?? {}).len == 0 ( code = candidate ) ) @@ -82,7 +82,7 @@ def handleCancelStudentRelease(*serve.Context c) ( ) def usableClaimOrFail(*serve.Context c) object ( - object claim = (classroomClaimDocs.findById(normalizeClassCode(c.param("code"))).unwrapOr(null) ?? {}) + object claim = (classroomClaimDocs.findById(normalizeClassCode(c.param("code"))).unwrap() ?? {}) object student = {} if claimIsUsable(claim, timestamp) ( student = loadStudent(claim.studentId.toStr()) diff --git a/src/classroom/classroom-schools.osl b/src/classroom/classroom-schools.osl index dc35c0e..c764830 100644 --- a/src/classroom/classroom-schools.osl +++ b/src/classroom/classroom-schools.osl @@ -40,7 +40,7 @@ def classroomPlanKey(string ownerId) string ( ) def planMemberIds(string key) array ( - object school = (schoolDocs.findById(key).unwrapOr(null) ?? {}) + object school = (schoolDocs.findById(key).unwrap() ?? {}) if school.len == 0 ( return [key] ) @@ -264,7 +264,7 @@ def handleAdminListSchools(*serve.Context c) ( for i schools.len ( object school = schools[i].assert(object) string key = school["_id"].toStr() - rows.append({id: key, name: school.name, admins: (school.adminIds ?? []).assertElse(array, []).map(def(any id) any -> usernameForId(id.toStr())), plan: effectiveClassroomPlan((classroomPlanDocs.findById(key).unwrapOr(null) ?? {}), timestamp)}) + rows.append({id: key, name: school.name, admins: (school.adminIds ?? []).assertElse(array, []).map(def(any id) any -> usernameForId(id.toStr())), plan: effectiveClassroomPlan((classroomPlanDocs.findById(key).unwrap() ?? {}), timestamp)}) ) c.json(200, {ok: true, schools: rows}) ) @@ -299,5 +299,5 @@ def handleAdminCreateSchool(*serve.Context c) ( updatedAt: timestamp }) invalidateClassroomPool(adminId) - c.json(201, {ok: true, school: {id: id, name: name}, plan: effectiveClassroomPlan((classroomPlanDocs.findById(id).unwrapOr(null) ?? {}), timestamp)}) + c.json(201, {ok: true, school: {id: id, name: name}, plan: effectiveClassroomPlan((classroomPlanDocs.findById(id).unwrap() ?? {}), timestamp)}) ) diff --git a/src/classroom/classroom-switch.test.osl b/src/classroom/classroom-switch.test.osl index 3e8ea75..4c404b2 100644 --- a/src/classroom/classroom-switch.test.osl +++ b/src/classroom/classroom-switch.test.osl @@ -46,7 +46,7 @@ def loadStudent(string id) object ( ) def loadClass(string id) object ( - return (classDocs.findById(id).unwrapOr(null) ?? {}) + return (classDocs.findById(id).unwrap() ?? {}) ) void classDocs.insertOne({_id: "cls_admin", code: "ADMIN234", ownerId: "u_mist", owner: "mist"}) diff --git a/src/classroom/classrooms.osl b/src/classroom/classrooms.osl index 1a47af5..964cd3f 100644 --- a/src/classroom/classrooms.osl +++ b/src/classroom/classrooms.osl @@ -54,14 +54,14 @@ def loadClass(string id) object ( if id == "" ( return {} ) - return (classDocs.findById(id).unwrapOr(null) ?? {}) + return (classDocs.findById(id).unwrap() ?? {}) ) def loadStudent(string id) object ( if !isStudentUserId(id) ( return {} ) - return (studentDocs.findById(id).unwrapOr(null) ?? {}) + return (studentDocs.findById(id).unwrap() ?? {}) ) def studentForUsername(string username) object ( @@ -126,7 +126,7 @@ def studentsForPlanOwner(string ownerId) array ( ) def classroomPlanFor(string ownerId) object ( - return effectiveClassroomPlan((classroomPlanDocs.findById(classroomPlanKey(ownerId)).unwrapOr(null) ?? {}), timestamp) + return effectiveClassroomPlan((classroomPlanDocs.findById(classroomPlanKey(ownerId)).unwrap() ?? {}), timestamp) ) def classroomPlanLock(string ownerId) string ( @@ -976,7 +976,7 @@ def handleCreateAssignment(*serve.Context c) ( ) def classAssignmentOrFail(*serve.Context c, object classDoc) object ( - object assignment = (assignmentDocs.findById(c.param("aid")).unwrapOr(null) ?? {}) + object assignment = (assignmentDocs.findById(c.param("aid")).unwrap() ?? {}) if assignment.len == 0 or assignment.classId.toStr() != classDoc["_id"].toStr() ( c.notFound("assignment not found") return {} @@ -994,7 +994,7 @@ def handleGetAssignment(*serve.Context c) ( array rows = [] for i students.len ( object student = students[i].assert(object) - object submission = (submissionDocs.findById(assignmentId ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}) + object submission = (submissionDocs.findById(assignmentId ++ ":" ++ student["_id"].toStr()).unwrap() ?? {}) rows.append({ student: {id: student["_id"], displayName: student.displayName}, submission: if submission.len == 0 then null else submission, @@ -1031,7 +1031,7 @@ def handleReviewSubmission(*serve.Context c) ( if classDoc.len == 0 return object assignment = classAssignmentOrFail(c, classDoc) if assignment.len == 0 return - object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ c.param("sid")).unwrapOr(null) ?? {}) + object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ c.param("sid")).unwrap() ?? {}) if submission.len == 0 ( c.notFound("this student has not started the assignment") return @@ -1076,7 +1076,7 @@ def studentAssignmentRows(object student) array ( array rows = [] for i assignments.len ( object assignment = assignments[i].assert(object) - object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}) + object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrap() ?? {}) rows.append({ id: assignment["_id"], title: assignment.title, @@ -1118,7 +1118,7 @@ def handleGetStudentClassroom(*serve.Context c) ( def studentAssignmentOrFail(*serve.Context c) object ( object student = loadStudent(contextString(c, "userId")) - object assignment = (assignmentDocs.findById(c.param("aid")).unwrapOr(null) ?? {}) + object assignment = (assignmentDocs.findById(c.param("aid")).unwrap() ?? {}) if student.len == 0 or assignment.len == 0 or assignment.classId.toStr() != student.classId.toStr() ( c.notFound("assignment not found") return {} @@ -1189,7 +1189,7 @@ def startSubmissionLocked(*serve.Context c, object student, object assignment, s string lockName = "classroom-submission-" ++ submissionId sync.lock(lockName) defer sync.unlock(lockName) - object existing = (submissionDocs.findById(submissionId).unwrapOr(null) ?? {}) + object existing = (submissionDocs.findById(submissionId).unwrap() ?? {}) if existing.len > 0 ( auto loaded = loadProject(existing.projectId.toStr()) if loaded.ok ( @@ -1243,7 +1243,7 @@ def handleTurnInAssignment(*serve.Context c) ( if found.len == 0 return object student = found.student.assert(object) object assignment = found.assignment.assert(object) - object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}) + object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrap() ?? {}) if submission.len == 0 or !submissionCanTurnIn(submission) ( c.badRequest("start the assignment before turning it in") return @@ -1274,7 +1274,7 @@ def handleUnsubmitAssignment(*serve.Context c) ( if found.len == 0 return object student = found.student.assert(object) object assignment = found.assignment.assert(object) - object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrapOr(null) ?? {}) + object submission = (submissionDocs.findById(assignment["_id"].toStr() ++ ":" ++ student["_id"].toStr()).unwrap() ?? {}) if submission.len == 0 or !submissionCanUnsubmit(submission) ( c.badRequest("this work is not waiting for your teacher") return @@ -1359,7 +1359,7 @@ def handleAdminGetClassroomPlan(*serve.Context c) ( c.badRequest("Rotur user not found") return ) - c.json(200, {ok: true, username: usernameForId(userId), stored: (classroomPlanDocs.findById(userId).unwrapOr(null) ?? {}), plan: classroomPlanFor(userId), usage: classroomUsage(userId)}) + c.json(200, {ok: true, username: usernameForId(userId), stored: (classroomPlanDocs.findById(userId).unwrap() ?? {}), plan: classroomPlanFor(userId), usage: classroomUsage(userId)}) ) def handleAdminSetClassroomPlan(*serve.Context c) ( @@ -1367,7 +1367,7 @@ def handleAdminSetClassroomPlan(*serve.Context c) ( string userId = "" string schoolId = (body.schoolId ?? "").toStr() if schoolId != "" ( - if (schoolDocs.findById(schoolId).unwrapOr(null) ?? {}).len == 0 ( + if (schoolDocs.findById(schoolId).unwrap() ?? {}).len == 0 ( c.badRequest("school not found") return ) diff --git a/src/community/challenges.osl b/src/community/challenges.osl index 3513598..a3091f7 100644 --- a/src/community/challenges.osl +++ b/src/community/challenges.osl @@ -208,7 +208,7 @@ def challengeWinner(object space, array projects) object ( ) def handleInviteChallengeJudge(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or space.kind.toStr() != "challenge" ( c.notFound("challenge not found") return @@ -223,7 +223,7 @@ def handleInviteChallengeJudge(*serve.Context c) ( ) string requested = requestJSON(c).username.toStr().strip() string usernameKey = normalizeUsername(requested) - object profile = (profileSearchDocs.findById(usernameKey).unwrapOr(null) ?? {}) + object profile = (profileSearchDocs.findById(usernameKey).unwrap() ?? {}) if usernameKey == "" or profile.len == 0 ( c.notFound("user not found") return @@ -243,7 +243,7 @@ def handleInviteChallengeJudge(*serve.Context c) ( ) def handleJoinChallenge(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or space.kind.toStr() != "challenge" or !canViewSpace(space, c) ( c.notFound("challenge not found") return @@ -267,7 +267,7 @@ def handleJoinChallenge(*serve.Context c) ( ) def handleLeaveChallenge(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or space.kind.toStr() != "challenge" ( c.notFound("challenge not found") return @@ -284,7 +284,7 @@ def handleLeaveChallenge(*serve.Context c) ( ) array ids = spaceProjectIds(space) for i ids.len ( - object project = (projectSearchDocs.findById(ids[i].toStr()).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(ids[i].toStr()).unwrap() ?? {}) if project.len > 0 and searchEntryOwnedByContext(project, c) ( c.badRequest("remove your submission before leaving the challenge") return @@ -297,7 +297,7 @@ def handleLeaveChallenge(*serve.Context c) ( ) def handleRespondChallengeJudgeInvite(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !isChallengeJudgeInvitee(space, contextString(c, "username")) ( c.notFound("judge invitation not found") return @@ -325,7 +325,7 @@ def handleRespondChallengeJudgeInvite(*serve.Context c) ( ) def handleRemoveChallengeJudge(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canManageSpace(space, c) ( c.forbidden("you cannot manage this challenge") return @@ -365,7 +365,7 @@ def validChallengeCriterion(object space, string criterionId) boolean ( ) def handleScoreChallengeEntry(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) string projectId = c.param("project") if space.len == 0 or space.kind.toStr() != "challenge" or !spaceProjectIds(space).contains(projectId) ( c.notFound("challenge entry not found") @@ -379,7 +379,7 @@ def handleScoreChallengeEntry(*serve.Context c) ( c.badRequest("judging is not open") return ) - object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrap() ?? {}) if project.len > 0 and searchEntryOwnedByContext(project, c) ( c.forbidden("you cannot score your own entry") return @@ -424,7 +424,7 @@ def handleScoreChallengeEntry(*serve.Context c) ( ) def handleVoteChallengeEntry(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) string projectId = c.param("project") if space.len == 0 or space.kind.toStr() != "challenge" or !spaceProjectIds(space).contains(projectId) ( c.notFound("challenge entry not found") @@ -434,7 +434,7 @@ def handleVoteChallengeEntry(*serve.Context c) ( c.badRequest("community voting is not open") return ) - object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrap() ?? {}) if project.len > 0 and searchEntryOwnedByContext(project, c) ( c.forbidden("you cannot vote for your own entry") return @@ -460,7 +460,7 @@ def handleVoteChallengeEntry(*serve.Context c) ( ) def handlePublishChallengeResults(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or space.kind.toStr() != "challenge" or !canManageSpace(space, c) ( c.forbidden("you cannot manage this challenge") return diff --git a/src/community/comments.osl b/src/community/comments.osl index d87bec9..81e9d62 100644 --- a/src/community/comments.osl +++ b/src/community/comments.osl @@ -394,7 +394,7 @@ def commentPage(array allComments,*serve.Context c) object ( ) number totalRoots = roots.len number requestedLimit = c.queryInt("limit", 0) - if requestedLimit <= 0 or c.queryBool("all", false).unwrapOr(false) ( + if requestedLimit <= 0 or c.queryBool("all", false).unwrap() ( return {comments: comments, totalRoots: totalRoots, nextOffset: totalRoots, issueCounts: issueCounts} ) number offset = clampNumber(c.queryInt("offset", 0), 0, totalRoots) diff --git a/src/community/community-user-records.osl b/src/community/community-user-records.osl index d26853b..13b68d9 100644 --- a/src/community/community-user-records.osl +++ b/src/community/community-user-records.osl @@ -231,7 +231,7 @@ def renameUserCommunityRecords(string oldKey, string newKey, string newName) boo if normalizeUsername(playtime.username.toStr()) == oldKey ( string oldId = playtime["_id"].toStr() string newId = playtime.projectId.toStr() ++ ":" ++ newKey - object existing = (playtimeDocs.findById(newId).unwrapOr(null) ?? {}) + object existing = (playtimeDocs.findById(newId).unwrap() ?? {}) if existing.len > 0 and newId != oldId ( playtime.duration = playtime.duration.toNum() + existing.duration.toNum() ) @@ -240,7 +240,7 @@ def renameUserCommunityRecords(string oldKey, string newKey, string newName) boo putDocument(playtimeDocs, newId, playtime) ) ) - object session = (playtimeSessionDocs.findById(oldKey).unwrapOr(null) ?? {}) + object session = (playtimeSessionDocs.findById(oldKey).unwrap() ?? {}) if session.len > 0 ( session.username = newName void playtimeSessionDocs.deleteOne({_id: oldKey}) diff --git a/src/community/development.osl b/src/community/development.osl index 4658f70..920ad22 100644 --- a/src/community/development.osl +++ b/src/community/development.osl @@ -31,7 +31,7 @@ def nowSeconds() number ( ) def developmentQuota() object ( - object stored = (developmentDocs.findById("quota").unwrapOr(null) ?? {}) + object stored = (developmentDocs.findById("quota").unwrap() ?? {}) if stored.len == 0 ( return {remaining: -1, reset: 0} ) @@ -85,7 +85,7 @@ def developmentSnapshot() object ( if developmentCache.has("pulls") ( return developmentCache.get("pulls").assertElse(object, {pulls: [], updated: 0}) ) - object stored = (developmentDocs.findById("pulls").unwrapOr(null) ?? {}) + object stored = (developmentDocs.findById("pulls").unwrap() ?? {}) if stored.len == 0 ( return {pulls: [], updated: 0} ) diff --git a/src/community/like-milestones.osl b/src/community/like-milestones.osl index e49214e..a93f99a 100644 --- a/src/community/like-milestones.osl +++ b/src/community/like-milestones.osl @@ -14,7 +14,7 @@ def notifyLikeMilestones(string target, string kind, string contentId, number be string lockName = "like-milestone:" ++ key sync.lock(lockName) defer sync.unlock(lockName) - object previous = (likeMilestoneDocs.findById(key).unwrapOr(null) ?? {}) + object previous = (likeMilestoneDocs.findById(key).unwrap() ?? {}) number notifiedThrough = (previous.notifiedThrough ?? 0).toNum() array milestones = crossedLikeMilestones(before, after, notifiedThrough) for i milestones.len ( diff --git a/src/community/like-milestones.test.osl b/src/community/like-milestones.test.osl index 9046d21..873a67d 100644 --- a/src/community/like-milestones.test.osl +++ b/src/community/like-milestones.test.osl @@ -136,7 +136,7 @@ syncFollowerMilestones("mist") testing.assert(sent.len == 13 and sent[13].data.milestone == 50, "follower milestones use the profile's count, private followers included") testing.assert(sent[13].data.path == "/users/mist", "follower milestones link to the profile") syncFollowerMilestones("hidden") -testing.assert(sent.len == 13 and (likeMilestoneDocs.findById("observed:followers:hidden").unwrapOr(null) ?? {}).len == 0, "a profile that hides its count records nothing") +testing.assert(sent.len == 13 and (likeMilestoneDocs.findById("observed:followers:hidden").unwrap() ?? {}).len == 0, "a profile that hides its count records nothing") milestoneDb.close() void fs.remove(path) void fs.remove(path ++ "-wal") diff --git a/src/community/news.osl b/src/community/news.osl index 3cd5fac..3b05b06 100644 --- a/src/community/news.osl +++ b/src/community/news.osl @@ -421,7 +421,7 @@ def handleViewNews(*serve.Context c) ( def migratePolicyNewsPosts() boolean ( string migrationId = "migration:news-policy-posts-v2" - if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrap() ?? {}).len > 0 ( return true ) array titles = [ diff --git a/src/community/playtime-diagnostics.osl b/src/community/playtime-diagnostics.osl index ad94ca0..2a63546 100644 --- a/src/community/playtime-diagnostics.osl +++ b/src/community/playtime-diagnostics.osl @@ -14,7 +14,7 @@ def playtimeIdentity(string username) string ( def beginPlaytimeSession(string projectId, string username, string sessionId) boolean ( string userId = userIdForUsername(username) string identityKey = playtimeIdentity(username) - object session = (playtimeSessionDocs.findById(sessionId).unwrapOr(null) ?? {}) + object session = (playtimeSessionDocs.findById(sessionId).unwrap() ?? {}) if session.len == 0 or session.projectId.toStr() != projectId or timestamp - session.lastSeen.toNum() > 120000 ( putDocument(playtimeSessionDocs, sessionId, { _id: sessionId, @@ -39,7 +39,7 @@ def touchRecentProjectActivity(string projectId, string username) boolean ( string playtimeLock = "playtime:" ++ playtimeId sync.lock(playtimeLock) defer sync.unlock(playtimeLock) - object playtime = (playtimeDocs.findById(playtimeId).unwrapOr(null) ?? {}) + object playtime = (playtimeDocs.findById(playtimeId).unwrap() ?? {}) if playtime.len == 0 ( playtime = {_id: playtimeId, projectId: projectId, username: username, userId: userId, duration: 0, updated: timestamp} ) else ( @@ -54,7 +54,7 @@ def touchRecentProjectActivity(string projectId, string username) boolean ( def creditPlaytimeSession(string projectId, string username, string sessionId, boolean finished) number ( string userId = userIdForUsername(username) - object session = (playtimeSessionDocs.findById(sessionId).unwrapOr(null) ?? {}) + object session = (playtimeSessionDocs.findById(sessionId).unwrap() ?? {}) if session.len == 0 or session.projectId.toStr() != projectId ( return 0 ) @@ -78,7 +78,7 @@ def creditPlaytimeLocked(string playtimeId, string projectId, string username, s string playtimeLock = "playtime:" ++ playtimeId sync.lock(playtimeLock) defer sync.unlock(playtimeLock) - object playtime = (playtimeDocs.findById(playtimeId).unwrapOr(null) ?? {}) + object playtime = (playtimeDocs.findById(playtimeId).unwrap() ?? {}) if playtime.len == 0 ( playtime = {_id: playtimeId, projectId: projectId, username: username, userId: userId, duration: 0, updated: timestamp} ) diff --git a/src/community/project-feedback.osl b/src/community/project-feedback.osl index 6fd0af9..21b164c 100644 --- a/src/community/project-feedback.osl +++ b/src/community/project-feedback.osl @@ -43,7 +43,7 @@ def handleUpdateProjectFeedback(*serve.Context c) ( c.forbidden("not your project") return ) - object feedback = (feedbackDocs.findById(c.param("feedback")).unwrapOr(null) ?? {}) + object feedback = (feedbackDocs.findById(c.param("feedback")).unwrap() ?? {}) if feedback.len == 0 or feedback.projectId.toStr() != c.param("id") ( c.notFound("feedback not found") return @@ -144,7 +144,7 @@ def handleSaveProjectReview(*serve.Context c) ( reviewerId = normalizeUsername(contextString(c, "username")) ) string reviewId = project.id.toStr() ++ ":" ++ reviewerId - object existing = (reviewDocs.findById(reviewId).unwrapOr(null) ?? {}) + object existing = (reviewDocs.findById(reviewId).unwrap() ?? {}) number created = timestamp if existing.len > 0 ( created = existing.created.toNum() diff --git a/src/community/releases.osl b/src/community/releases.osl index 927f65d..29bf291 100644 --- a/src/community/releases.osl +++ b/src/community/releases.osl @@ -127,7 +127,7 @@ def handleCreateRelease(*serve.Context c) ( ) def handleGetReleaseProjectJson(*serve.Context c) ( - object release = (releaseDocs.findById(c.param("release")).unwrapOr(null) ?? {}) + object release = (releaseDocs.findById(c.param("release")).unwrap() ?? {}) if release.len == 0 or release.projectId.toStr() != c.param("id") ( c.notFound("release not found") return @@ -168,7 +168,7 @@ def handleDeleteRelease(*serve.Context c) ( c.forbidden("not your project") return ) - object release = (releaseDocs.findById(c.param("release")).unwrapOr(null) ?? {}) + object release = (releaseDocs.findById(c.param("release")).unwrap() ?? {}) if release.len == 0 or release.projectId.toStr() != project.id.toStr() ( c.notFound("release not found") return diff --git a/src/community/remote-milestones.osl b/src/community/remote-milestones.osl index e51b5eb..54a8c37 100644 --- a/src/community/remote-milestones.osl +++ b/src/community/remote-milestones.osl @@ -24,7 +24,7 @@ def observeRemoteMilestone(string target, string kind, string id, number count, string key = "observed:" ++ kind ++ ":" ++ id sync.lock(key) defer sync.unlock(key) - object previous = (likeMilestoneDocs.findById(key).unwrapOr(null) ?? {}) + object previous = (likeMilestoneDocs.findById(key).unwrap() ?? {}) number before = count - 1 if previous.contains("count") ( before = previous.count.toNum() diff --git a/src/community/roadmap.osl b/src/community/roadmap.osl index b8fdd0d..2701834 100644 --- a/src/community/roadmap.osl +++ b/src/community/roadmap.osl @@ -102,7 +102,7 @@ def handleVoteIdea(*serve.Context c) ( ) def handleVoteIdeaLocked(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrap() ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -154,7 +154,7 @@ def handleVoteIdeaLocked(*serve.Context c) ( ) def handleGetIdeaComments(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrap() ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -165,7 +165,7 @@ def handleGetIdeaComments(*serve.Context c) ( ) def handleCreateIdeaComment(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrap() ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -204,7 +204,7 @@ def handleCreateIdeaComment(*serve.Context c) ( ) def handleDeleteIdeaComment(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrap() ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -228,7 +228,7 @@ def handleDeleteIdeaComment(*serve.Context c) ( ) def handleEditIdeaComment(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrap() ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -247,7 +247,7 @@ def handleEditIdeaComment(*serve.Context c) ( ) def handleReactIdeaComment(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrap() ?? {}) if idea.len == 0 ( c.notFound("idea not found") return @@ -256,7 +256,7 @@ def handleReactIdeaComment(*serve.Context c) ( ) def handleUpdateIdea(*serve.Context c) ( - object idea = (ideaDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object idea = (ideaDocs.findById(c.param("id")).unwrap() ?? {}) if idea.len == 0 ( c.notFound("idea not found") return diff --git a/src/community/social.osl b/src/community/social.osl index 44d55aa..5974656 100644 --- a/src/community/social.osl +++ b/src/community/social.osl @@ -221,7 +221,7 @@ def userPlaytimeLibrary(string name,*serve.Context c) array ( array library = [] for i savedProjects.len ( string projectId = savedProjects[i].toStr() - object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrap() ?? {}) boolean libraryPublic = !hiddenProjects.contains(projectId) boolean include = libraryPublic and project.len > 0 and projectVisibility(project) == "public" if !include and project.len > 0 ( @@ -276,7 +276,7 @@ def handleGetUser(*serve.Context c) ( ) ) if !featuredIncluded ( - object featured = (projectSearchDocs.findById(featuredId).unwrapOr(null) ?? {}) + object featured = (projectSearchDocs.findById(featuredId).unwrap() ?? {}) if featured.len > 0 and featured.shared == true and featured.ownerKey.toStr() == key and projectsVisibleTo([featured], c).len > 0 ( projects.append(featured) ) @@ -500,7 +500,7 @@ def handleGetUserProjects(*serve.Context c) ( if userIdForUsername(name) == "" ( discoverUserIdentity(name) ) - boolean includeUnshared = isViewerOwner(c, name) and c.queryBool("all", false).unwrapOr(false) + boolean includeUnshared = isViewerOwner(c, name) and c.queryBool("all", false).unwrap() array projects = projectsVisibleTo(ownerIndexEntries(name, includeUnshared), c) number requestedLimit = c.queryInt("limit", 0) if requestedLimit > 0 ( @@ -722,7 +722,7 @@ def handleSetLibraryProjectVisibility(*serve.Context c) ( ) def activityProjectVisibility(string projectId) string ( - object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrap() ?? {}) if project.len > 0 and projectIsViewable(project) ( return projectVisibility(project) ) @@ -777,7 +777,7 @@ def handleGetActivity(*serve.Context c) ( string author = normalizeUsername(review.author.toStr()) string projectId = review.projectId.toStr() if selectedUsers.contains(author) and activityProjectVisibility(projectId) == "public" ( - object project = (projectSearchDocs.findById(projectId).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(projectId).unwrap() ?? {}) items.append({type: "review", actor: review.author, projectId: review.projectId, projectTitle: project.title, rating: review.rating, message: review.message, created: review.edited}) reviewItems += 1 ) diff --git a/src/community/space-comments.osl b/src/community/space-comments.osl index 0e339fe..5f18d91 100644 --- a/src/community/space-comments.osl +++ b/src/community/space-comments.osl @@ -1,5 +1,5 @@ def handleGetSpaceComments(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -10,7 +10,7 @@ def handleGetSpaceComments(*serve.Context c) ( ) def handleCreateSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -50,7 +50,7 @@ def handleCreateSpaceComment(*serve.Context c) ( ) def handleDeleteSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -74,7 +74,7 @@ def handleDeleteSpaceComment(*serve.Context c) ( ) def handleEditSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -93,7 +93,7 @@ def handleEditSpaceComment(*serve.Context c) ( ) def handlePinSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -117,7 +117,7 @@ def handlePinSpaceComment(*serve.Context c) ( ) def handleReactSpaceComment(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return diff --git a/src/community/space-memberships.osl b/src/community/space-memberships.osl index 17ba901..b55ab2d 100644 --- a/src/community/space-memberships.osl +++ b/src/community/space-memberships.osl @@ -51,7 +51,7 @@ def syncSpaceMemberships(object space) boolean ( array keys = spaceRelatedUserKeys(space) string signature = json.stringify(keys) string stateId = "space:" ++ spaceId - object state = (spaceMemberDocs.findById(stateId).unwrapOr(null) ?? {}) + object state = (spaceMemberDocs.findById(stateId).unwrap() ?? {}) if state.len > 0 and state.signature.toStr() == signature ( return true ) @@ -87,7 +87,7 @@ def deleteSpaceMemberships(string spaceId) boolean ( def migrateSpaceMemberships() boolean ( string migrationId = "migration:space-members-v1" - if (spaceMemberDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( + if (spaceMemberDocs.findById(migrationId).unwrap() ?? {}).len > 0 ( return true ) array previous = spaceMemberDocs.all() diff --git a/src/community/space-responses.osl b/src/community/space-responses.osl index 068f4ec..177fd25 100644 --- a/src/community/space-responses.osl +++ b/src/community/space-responses.osl @@ -99,7 +99,7 @@ def spaceListResponse(object space,*serve.Context c) object ( number projectCount = 0 boolean canManage = canManageSpace(space, c) for i ids.len ( - object project = (projectSearchDocs.findById(ids[i].toStr()).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(ids[i].toStr()).unwrap() ?? {}) boolean hidden = projectHiddenFrom(project, c) if project.len > 0 and !hidden and (project.shared == true or project.visibility.toStr() == "unlisted" or canManage) ( projectCount += 1 diff --git a/src/community/spaces.osl b/src/community/spaces.osl index 9f579a8..b8e13f9 100644 --- a/src/community/spaces.osl +++ b/src/community/spaces.osl @@ -90,7 +90,7 @@ def handleListSpaces(*serve.Context c) ( ) def handleGetSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -204,7 +204,7 @@ def handleCreateSpace(*serve.Context c) ( ) def handleUpdateSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -352,7 +352,7 @@ def handleUpdateSpace(*serve.Context c) ( ) def handleDeleteSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -372,7 +372,7 @@ def handleDeleteSpace(*serve.Context c) ( ) def handleSetSpaceThumbnail(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -401,8 +401,8 @@ def handleSetSpaceThumbnail(*serve.Context c) ( ) def handleAddSpaceProject(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) - object project = (projectSearchDocs.findById(c.param("project")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) + object project = (projectSearchDocs.findById(c.param("project")).unwrap() ?? {}) if space.len == 0 or project.len == 0 ( c.notFound("space or project not found") return @@ -445,12 +445,12 @@ def handleAddSpaceProject(*serve.Context c) ( ) def handleRemoveSpaceProject(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return ) - object project = (projectSearchDocs.findById(c.param("project")).unwrapOr(null) ?? {}) + object project = (projectSearchDocs.findById(c.param("project")).unwrap() ?? {}) boolean allowed = canManageSpace(space, c) if project.len > 0 ( allowed = allowed or searchEntryOwnedByContext(project, c) @@ -477,7 +477,7 @@ def handleRemoveSpaceProject(*serve.Context c) ( ) def handleFollowSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return @@ -492,7 +492,7 @@ def handleFollowSpace(*serve.Context c) ( ) def handleUnfollowSpace(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -513,7 +513,7 @@ def handleMySpaces(*serve.Context c) ( object seen = {} for i memberships.len ( object membership = memberships[i].assert(object) - object space = (spaceDocs.findById(membership.spaceId.toStr()).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(membership.spaceId.toStr()).unwrap() ?? {}) if space.len > 0 ( seen[space["_id"].toStr()] = true stored.append(space) @@ -544,7 +544,7 @@ def handleMySpaces(*serve.Context c) ( ) def handleGetSpaceManagement(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -557,7 +557,7 @@ def handleGetSpaceManagement(*serve.Context c) ( ) def handleInviteSpaceCurator(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -572,7 +572,7 @@ def handleInviteSpaceCurator(*serve.Context c) ( c.badRequest("choose another user") return ) - object profile = (profileSearchDocs.findById(usernameKey).unwrapOr(null) ?? {}) + object profile = (profileSearchDocs.findById(usernameKey).unwrap() ?? {}) if profile.len == 0 ( c.notFound("user not found") return @@ -599,7 +599,7 @@ def handleInviteSpaceCurator(*serve.Context c) ( ) def handleRespondSpaceCuratorInvite(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -640,7 +640,7 @@ def handleRespondSpaceCuratorInvite(*serve.Context c) ( ) def handleRemoveSpaceCurator(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -661,7 +661,7 @@ def handleRemoveSpaceCurator(*serve.Context c) ( ) def handleCancelSpaceCuratorInvite(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 ( c.notFound("space not found") return @@ -698,7 +698,7 @@ def handleReactSpace(*serve.Context c) ( ) def handleReactSpaceLocked(*serve.Context c) ( - object space = (spaceDocs.findById(c.param("id")).unwrapOr(null) ?? {}) + object space = (spaceDocs.findById(c.param("id")).unwrap() ?? {}) if space.len == 0 or !canViewSpace(space, c) ( c.notFound("space not found") return diff --git a/src/core/database.osl b/src/core/database.osl index f427bf4..0e3a2cd 100644 --- a/src/core/database.osl +++ b/src/core/database.osl @@ -166,7 +166,7 @@ def deleteProjectCommunityRecords(string projectId) boolean ( def syncSearchProject(object project) boolean ( object entry = indexEntryFromProject(project) if entry.remixRoot.toStr() == "" and entry.remixParent.toStr() != "" ( - object parent = (projectSearchDocs.findById(entry.remixParent.toStr()).unwrapOr(null) ?? {}) + object parent = (projectSearchDocs.findById(entry.remixParent.toStr()).unwrap() ?? {}) if parent.len > 0 ( entry.remixRoot = parent.id if parent.contains("remixRoot") and parent.remixRoot.toStr() != "" ( @@ -201,7 +201,7 @@ def removeSearchProject(string id) boolean ( def migratePullCommentCounts() boolean ( string migrationId = "migration:pull-comment-count-v1" - if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrap() ?? {}).len > 0 ( return true ) array pulls = pullDocs.all() @@ -308,7 +308,7 @@ def validPreviewKey(string projectId, string key) boolean ( if key == "" ( return false ) - object preview = previewDocs.findOne({projectId: projectId, key: key}).unwrapOr(null) ?? {} + object preview = previewDocs.findOne({projectId: projectId, key: key}).unwrap() ?? {} if preview.len == 0 ( return false ) @@ -323,9 +323,9 @@ def projectPlaytimeRecord(string projectId, string username) object ( if identityKey == "" ( identityKey = normalizeUsername(username) ) - object entry = (playtimeDocs.findById(projectId ++ ":" ++ identityKey).unwrapOr(null) ?? {}) + object entry = (playtimeDocs.findById(projectId ++ ":" ++ identityKey).unwrap() ?? {}) if entry.len == 0 and identityKey != normalizeUsername(username) ( - entry = (playtimeDocs.findById(projectId ++ ":" ++ normalizeUsername(username)).unwrapOr(null) ?? {}) + entry = (playtimeDocs.findById(projectId ++ ":" ++ normalizeUsername(username)).unwrap() ?? {}) ) return entry ) diff --git a/src/git/pulls.osl b/src/git/pulls.osl index 5898df9..edb277a 100644 --- a/src/git/pulls.osl +++ b/src/git/pulls.osl @@ -72,7 +72,7 @@ def livePullResponse(object pull, string baseCommit, string headCommit) object ( ) def pullDocument(string targetId, string index) object ( - return (pullDocs.findById(targetId ++ ":" ++ index).unwrapOr(null) ?? {}) + return (pullDocs.findById(targetId ++ ":" ++ index).unwrap() ?? {}) ) def pullCommentKey(object pull) string ( diff --git a/src/projects/project-read.osl b/src/projects/project-read.osl index 4fff1d5..25d95b0 100644 --- a/src/projects/project-read.osl +++ b/src/projects/project-read.osl @@ -16,7 +16,7 @@ def handleGetProject(*serve.Context c) ( object response = projectResponse(project, c) object jsonAccess = projectJsonAccess(project, c) if project.shared == true and project.contains("publicRelease") and project.publicRelease.toStr() != "" and response.ownerBanned != true and jsonAccess.allowed == true ( - object release = (releaseDocs.findById(project.publicRelease.toStr()).unwrapOr(null) ?? {}) + object release = (releaseDocs.findById(project.publicRelease.toStr()).unwrap() ?? {}) if release.len > 0 and release.contains("jsonUrl") ( response.projectJsonUrl = keyedJsonUrl(release.jsonUrl.toStr(), jsonAccess) response.releaseVersion = release.version @@ -61,7 +61,7 @@ def handleGetProjectTrustedExtensions(*serve.Context c) ( ) array jsonUrls = [projectJsonBaseUrl(project)] if project.shared == true and (project.publicRelease ?? "").toStr() != "" ( - object release = (releaseDocs.findById(project.publicRelease.toStr()).unwrapOr(null) ?? {}) + object release = (releaseDocs.findById(project.publicRelease.toStr()).unwrap() ?? {}) if (release.jsonUrl ?? "").toStr() != "" ( jsonUrls.append(release.jsonUrl.toStr()) ) diff --git a/src/projects/project-remix.osl b/src/projects/project-remix.osl index f6f9631..f0865f0 100644 --- a/src/projects/project-remix.osl +++ b/src/projects/project-remix.osl @@ -74,7 +74,7 @@ def handleGetRemixTree(*serve.Context c) ( array nodes = [] object seen = {} - object root = (projectSearchDocs.findById(rootId).unwrapOr(null) ?? {}) + object root = (projectSearchDocs.findById(rootId).unwrap() ?? {}) if root.len > 0 ( nodes.append(root) seen[rootId] = true @@ -391,7 +391,7 @@ def createFork(PreparedFork prepared, ForkRequest request, ForkOutcome outcome) gitGraph: forkHistory.graph, collaborators: [] } - object parentEntry = (projectSearchDocs.findById(parentId).unwrapOr(null) ?? {}) + object parentEntry = (projectSearchDocs.findById(parentId).unwrap() ?? {}) if parentEntry.len > 0 and parentEntry.contains("remixRoot") and parentEntry.remixRoot.toStr() != "" ( project.remixRoot = parentEntry.remixRoot ) diff --git a/src/storage/r2.osl b/src/storage/r2.osl index f751c19..0c3c5bb 100644 --- a/src/storage/r2.osl +++ b/src/storage/r2.osl @@ -79,7 +79,7 @@ def handleGetThumbnail(*serve.Context c) ( ) def thumbnailAccess(string id, boolean hasKey) object ( - object entry = (projectSearchDocs.findById(id).unwrapOr(null) ?? {}) + object entry = (projectSearchDocs.findById(id).unwrap() ?? {}) if entry.len > 0 and projectOwnerBanned(entry) ( return {found: true, ownerBanned: true, isPublic: false, viewKey: ""} ) diff --git a/src/storage/storage-usage.osl b/src/storage/storage-usage.osl index d245065..e5e94c4 100644 --- a/src/storage/storage-usage.osl +++ b/src/storage/storage-usage.osl @@ -85,7 +85,7 @@ def storageInventory() object ( def backfillProjectHistoryBytes() ( string migrationId = "migration:project-history-bytes-v1" - if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrap() ?? {}).len > 0 ( return ) object listing = storageInventory() @@ -119,7 +119,7 @@ def backfillProjectHistoryBytes() ( def backfillReleaseJsonBytes() boolean ( string migrationId = "migration:release-json-bytes-v1" - if (diagnosticDocs.findById(migrationId).unwrapOr(null) ?? {}).len > 0 ( + if (diagnosticDocs.findById(migrationId).unwrap() ?? {}).len > 0 ( return true ) object listing = storageInventory() From 8d947dd91aa1698934c7c576625f197231baced5 Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 28 Nov 2026 02:24:22 +0000 Subject: [PATCH 4/5] Check Gitea responses by status, since OSL 24 responses have no success field --- src/git/gitea.osl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/git/gitea.osl b/src/git/gitea.osl index b6a3831..dd00786 100644 --- a/src/git/gitea.osl +++ b/src/git/gitea.osl @@ -23,7 +23,7 @@ def giteaPost(string path, object body, string sudoUser) object ( ) def parseGiteaObject(object resp) object ( - if !resp.success ( + if resp.status < 200 or resp.status >= 300 ( return {ok: false, error: "gitea request failed", status: resp.status} ) auto parsed = json.parse(resp.body, {type: "object"}) @@ -34,7 +34,7 @@ def parseGiteaObject(object resp) object ( ) def parseGiteaArray(object resp) object ( - if !resp.success ( + if resp.status < 200 or resp.status >= 300 ( return {ok: false, error: "gitea request failed", status: resp.status} ) auto parsed = json.parse(resp.body, {type: "array"}) From 147459d6540f0cb34dc89caf1ff41ca8605015a5 Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:06:22 +0000 Subject: [PATCH 5/5] Pin CI to the final OSL 24.0.1 fix commit --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e51ab3e..749f0db 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - name: Install OSL env: - OSL_COMMIT: 44dde5ba5120c295617392cf05d098bd4a4c4b36 + OSL_COMMIT: f5e02b2e086ac7f7fb1d42a8215de47314660c73 run: | mkdir -p "$HOME/.local/bin" git clone --filter=blob:none https://git.rotur.dev/osl/.go /tmp/osl-source