diff --git a/.agents/skills/hypercerts-api/references/openapi.json b/.agents/skills/hypercerts-api/references/openapi.json index f246f19a..3dc5e899 100644 --- a/.agents/skills/hypercerts-api/references/openapi.json +++ b/.agents/skills/hypercerts-api/references/openapi.json @@ -4669,7 +4669,7 @@ "description": "Opaque cursor from the previous page, bound to sortDirection.", "schema": { "type": "string", - "maxLength": 32768 + "maxLength": 8192 } } ], diff --git a/.changeset/list-features-cursor-limit.md b/.changeset/list-features-cursor-limit.md new file mode 100644 index 00000000..f6318974 --- /dev/null +++ b/.changeset/list-features-cursor-limit.md @@ -0,0 +1,6 @@ +--- +'@hypercerts-org/happyview-modules': patch +'@hypercerts-org/api': patch +--- + +`listFeatures` now documents the same 8192-character cursor limit as the other list endpoints (it said 32768). Cursors the API returns are far shorter, so paging is unaffected. diff --git a/.changeset/shared-list-input-checks.md b/.changeset/shared-list-input-checks.md new file mode 100644 index 00000000..fe5bfba1 --- /dev/null +++ b/.changeset/shared-list-input-checks.md @@ -0,0 +1,5 @@ +--- +'@hypercerts-org/happyview-modules': patch +--- + +List endpoints now check paging cursors and repeated parameters the same way everywhere. A cursor that is empty or longer than 8192 characters is rejected with `cursor is malformed`; cursors the API returns are always shorter, so normal paging is unaffected. Repeated filters such as `authors` that arrive in an unexpected shape now fail with ` must use repeated query values` on every endpoint; HappyView already rejects those spellings before this check, so requests behave as before. diff --git a/AGENTS.md b/AGENTS.md index 99713c3d..efcb775c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,5 +8,5 @@ - `pnpm install:api` sends admin requests to a HappyView instance and uploads assets. Do not run it unless the user explicitly approves the target and token in the current conversation. - HTTP runtime tests use a task-owned local Compose project and disposable database. Do not target or tear down unrelated services; note that the Compose bridge network permits egress and the configured proxy is not network-level isolation. - Every new query endpoint needs a case in `happyview-modules/tooling/smoke-cases.js`. Add it to `happyview-modules/tooling/e2e.js` only if it has paging walks, count invariants or batch behaviour. When an endpoint's behavior changes, update the checks that cover it. -- Reuse and extend the canonical Lua helpers in `happyview-modules/lua/shared/` instead of writing a new copy in a handler or another shared file. Before writing a helper, search `happyview-modules/lua/shared/` and `happyview-modules/tooling/shared-helpers.registry.json` for an existing one; the lint only catches some copies. Families: DID, NSID, record URI/key, subject URI, datetime, handle/resolver, list cursor, list limit/includeTotal/sortDirection, query parameter helpers (`invalid`, `keys_only`, `scalar`), record view, actor view and batch request-target. Repeated-parameter (array) parsing has no shared helper yet. +- Reuse and extend the canonical Lua helpers in `happyview-modules/lua/shared/` instead of writing a new copy in a handler or another shared file. Before writing a helper, search `happyview-modules/lua/shared/` and `happyview-modules/tooling/shared-helpers.registry.json` for an existing one; the lint only catches some copies. Families: DID, NSID, record URI/key, subject URI, datetime, handle/resolver, list cursor, list limit/includeTotal/sortDirection, query parameter helpers (`invalid`, `keys_only`, `scalar`), record view, actor view and batch request-target. Repeated-parameter (array) parsing (`query_string_values` reads and bounds the list, `unique_query_values` validates and de-duplicates; the endpoint keeps its own item messages). - `pnpm lint` (so `pnpm check` and CI) runs `happyview-modules/tooling/lint-shared-helpers.js` on `lua/shared` and `lua/src`. Every top-level function defined in `lua/shared` is protected automatically: defining the same name in another shared file or in `lua/src` fails lint and names the file that owns it. Nothing to register for a new shared helper, but check the names already there first. `shared-helpers.registry.json` (paths relative to `happyview-modules/`) holds only lookalike name patterns and inline code patterns per family (`id`, `description`, `homes` = files where the patterns legitimately appear, `lookalikes`/`inline`) and the `allowlist`. To keep an existing copy, add `{file, family, symbol, reason}` to `allowlist` (`family` is `shared-helper` for a name defined in `lua/shared`; `symbol` is the function name or inline rule id; add `count` if it occurs more than once). The failure message prints a ready-made entry. An entry that no longer matches fails lint; delete it. The current allowlist is a baseline, not approval for new copies. diff --git a/docs/openapi.json b/docs/openapi.json index 016a763a..29cb65ea 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -4909,7 +4909,7 @@ "description": "Opaque cursor from the previous page, bound to sortDirection.", "schema": { "type": "string", - "maxLength": 32768 + "maxLength": 8192 } } ], diff --git a/docs/sources/lexicons/org.hypercerts.entity.listFeatures.json b/docs/sources/lexicons/org.hypercerts.entity.listFeatures.json index 1b103f57..c5898705 100644 --- a/docs/sources/lexicons/org.hypercerts.entity.listFeatures.json +++ b/docs/sources/lexicons/org.hypercerts.entity.listFeatures.json @@ -49,7 +49,7 @@ }, "cursor": { "type": "string", - "maxLength": 32768, + "maxLength": 8192, "description": "Opaque cursor from the previous page, bound to sortDirection." } } diff --git a/happyview-modules/lexicons/org.hypercerts.entity.listFeatures.json b/happyview-modules/lexicons/org.hypercerts.entity.listFeatures.json index 541057c2..677f5ec1 100644 --- a/happyview-modules/lexicons/org.hypercerts.entity.listFeatures.json +++ b/happyview-modules/lexicons/org.hypercerts.entity.listFeatures.json @@ -43,7 +43,7 @@ }, "cursor": { "type": "string", - "maxLength": 32768, + "maxLength": 8192, "description": "Opaque cursor from the previous page, bound to sortDirection." } } diff --git a/happyview-modules/lua/endpoints/getActorReactions.lua b/happyview-modules/lua/endpoints/getActorReactions.lua index 06728f04..e7de974e 100644 --- a/happyview-modules/lua/endpoints/getActorReactions.lua +++ b/happyview-modules/lua/endpoints/getActorReactions.lua @@ -160,6 +160,8 @@ local function actor_reaction_sort_key() ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" end +-- Not query_string_values: subjects is required, keeps duplicates in request order, and +-- reports the range as "subjects must contain 1 through 100 AT-URIs". local function feed_actor_reaction_subjects(actor, value) if value == nil then invalid("subjects is required") end diff --git a/happyview-modules/lua/endpoints/getReactionCounts.lua b/happyview-modules/lua/endpoints/getReactionCounts.lua index beec6883..a5a6c0dd 100644 --- a/happyview-modules/lua/endpoints/getReactionCounts.lua +++ b/happyview-modules/lua/endpoints/getReactionCounts.lua @@ -208,6 +208,8 @@ function ref_counts.run(failures, sql, values) return rows end +-- Not query_string_values: subjects is required, keeps duplicates in request order, stops +-- counting at 101 entries, and reports the range as "subjects must contain 1 through 100 AT-URIs". local function reaction_count_subjects() local value = params.subjects if value == nil then invalid("subjects is required") end diff --git a/happyview-modules/lua/endpoints/listAcknowledgements.lua b/happyview-modules/lua/endpoints/listAcknowledgements.lua index 34b3f876..ab7680a4 100644 --- a/happyview-modules/lua/endpoints/listAcknowledgements.lua +++ b/happyview-modules/lua/endpoints/listAcknowledgements.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -236,18 +279,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local function valid_cursor_timestamp(value) @@ -258,32 +306,10 @@ local function valid_cursor_timestamp(value) return valid_datetime(value) end -local function acknowledgement_array(key, format) - local value = params[key] - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function acknowledgement_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") elseif format == "at-uri" then @@ -292,12 +318,7 @@ local function acknowledgement_array(key, format) invalid("each " .. key .. " value must be a full AT-URI with a DID authority and valid collection NSID") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function acknowledgement_sort_expression() @@ -347,8 +368,8 @@ local function list_acknowledgements() limit = true, cursor = true, }) - local authors = acknowledgement_array("authors", "did") - local subjects = acknowledgement_array("subjects", "at-uri") + local authors = acknowledgement_filter_values("authors", "did") + local subjects = acknowledgement_filter_values("subjects", "at-uri") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, ACKNOWLEDGEMENT, valid_cursor_timestamp) diff --git a/happyview-modules/lua/endpoints/listActivities.lua b/happyview-modules/lua/endpoints/listActivities.lua index 210bdd03..646b8e99 100644 --- a/happyview-modules/lua/endpoints/listActivities.lua +++ b/happyview-modules/lua/endpoints/listActivities.lua @@ -234,6 +234,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local ACTIVITY = "org.hypercerts.claim.activity" local function query(sql, values) @@ -356,18 +399,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local function parse_include_total(values) @@ -380,32 +428,10 @@ local function parse_include_total(values) invalid("includeTotal must be true or false") end -local function activity_array(key, format) - local value = params[key] - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function activity_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") elseif format == "activityUri" then @@ -414,21 +440,7 @@ local function activity_array(key, format) invalid("each uris value must be a full org.hypercerts.claim.activity AT-URI with a DID authority") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique -end - -local function bind_values(values, items) - local placeholders = {} - for _, item in ipairs(items) do - values[#values + 1] = item - placeholders[#placeholders + 1] = "$" .. #values - end - return placeholders + end) end local function activity_contributor_match(values, dids) @@ -543,7 +555,7 @@ local function activity_list_response(search_enabled) if search_enabled then allowed.search = true else allowed.includeTotal = true end keys_only(params, allowed, "unknown query parameter: ") - local authors = activity_array("authors", "did") + local authors = activity_filter_values("authors", "did") local has_organization_record = scalar_or_boolean(params, "hasOrganizationRecord") if has_organization_record ~= nil then if has_organization_record == "true" then @@ -554,9 +566,9 @@ local function activity_list_response(search_enabled) invalid("hasOrganizationRecord must be true or false") end end - local contributors = activity_array("contributors", "did") - local involved_actors = activity_array("involvedActors", "did") - local uris = activity_array("uris", "activityUri") + local contributors = activity_filter_values("contributors", "did") + local involved_actors = activity_filter_values("involvedActors", "did") + local uris = activity_filter_values("uris", "activityUri") local search if search_enabled then search = scalar(params, "search") diff --git a/happyview-modules/lua/endpoints/listActorFollowers.lua b/happyview-modules/lua/endpoints/listActorFollowers.lua index 773b97cd..73d7f7f5 100644 --- a/happyview-modules/lua/endpoints/listActorFollowers.lua +++ b/happyview-modules/lua/endpoints/listActorFollowers.lua @@ -242,27 +242,6 @@ local function query(sql, values) return result end -local function valid_follow_uri(value) - local valid, collection = valid_record_uri(value) - return valid and collection == FOLLOW -end - -local function cursor_decode(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_follow_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value -end - local function build_actor_follow_query(mode, actor, limit, cursor, direction) local filters, values = { "collection = $1", account_follow_filter_sql() }, { FOLLOW } values[#values + 1] = actor @@ -326,7 +305,7 @@ local function list_actor_follows(mode) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, FOLLOW) local views, next_cursor, total_count = query_actor_follows(mode, actor, limit, cursor, direction) local response = { [mode] = toarray(views), totalCount = total_count } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/listActorFollowing.lua b/happyview-modules/lua/endpoints/listActorFollowing.lua index b41ada88..486533c6 100644 --- a/happyview-modules/lua/endpoints/listActorFollowing.lua +++ b/happyview-modules/lua/endpoints/listActorFollowing.lua @@ -242,27 +242,6 @@ local function query(sql, values) return result end -local function valid_follow_uri(value) - local valid, collection = valid_record_uri(value) - return valid and collection == FOLLOW -end - -local function cursor_decode(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_follow_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value -end - local function build_actor_follow_query(mode, actor, limit, cursor, direction) local filters, values = { "collection = $1", account_follow_filter_sql() }, { FOLLOW } values[#values + 1] = actor @@ -326,7 +305,7 @@ local function list_actor_follows(mode) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, FOLLOW) local views, next_cursor, total_count = query_actor_follows(mode, actor, limit, cursor, direction) local response = { [mode] = toarray(views), totalCount = total_count } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/listAttachments.lua b/happyview-modules/lua/endpoints/listAttachments.lua index c67facd3..948e8913 100644 --- a/happyview-modules/lua/endpoints/listAttachments.lua +++ b/happyview-modules/lua/endpoints/listAttachments.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -236,18 +279,23 @@ local function hydrate_attachment_views(views) hydrate_actor_views(authors, attachment_query) end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" @@ -265,39 +313,12 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end -local function attachment_array(params, key, validate, description) - local value = params[key] - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function attachment_filter_values(params, key, validate, description) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function attachment_subject_filter(where, values, subjects) @@ -371,13 +392,13 @@ local function list_attachments() limit = true, cursor = true, }) - local authors = attachment_array(params, "authors", valid_did, "valid DIDs") - local uris = attachment_array(params, "uris", valid_attachment_uri, + local authors = attachment_filter_values(params, "authors", valid_did, "valid DIDs") + local uris = attachment_filter_values(params, "uris", valid_attachment_uri, "full org.hypercerts.context.attachment AT-URIs with DID authorities") - local subjects = attachment_array(params, "subjects", function(value) + local subjects = attachment_filter_values(params, "subjects", function(value) return valid_record_uri(value) end, "full AT-URIs with DID authorities") - local content_types = attachment_array(params, "contentTypes") + local content_types = attachment_filter_values(params, "contentTypes") local limit = parse_list_limit(params) local direction = parse_sort_direction(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_attachment_uri) diff --git a/happyview-modules/lua/endpoints/listBadgeAwards.lua b/happyview-modules/lua/endpoints/listBadgeAwards.lua index 40c9e5fb..33f4df2c 100644 --- a/happyview-modules/lua/endpoints/listBadgeAwards.lua +++ b/happyview-modules/lua/endpoints/listBadgeAwards.lua @@ -28,6 +28,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function parse_include_total(values) local value = values.includeTotal if value == nil then return false end @@ -66,6 +109,13 @@ local function valid_bounded_record_uri(value) end -- luacheck: pop +local BADGE_DEFINITION_COLLECTION = "app.certified.badge.definition" + +local function valid_badge_definition_uri(value) + local valid, collection = valid_record_uri(value) + return valid and collection == BADGE_DEFINITION_COLLECTION +end + local function valid_datetime(value) if type(value) ~= "string" then return false end local year, month, day, hour, minute, second, suffix = value:match( @@ -254,11 +304,6 @@ local function valid_badge_award_uri(value) return valid and collection == AWARD end -local function valid_badge_definition_uri(value) - local valid, collection = valid_record_uri(value) - return valid and collection == DEFINITION -end - local function query(sql, values) if db.backend() ~= "postgres" then error("BadgeAwardQueryFailed: badge award API requires PostgreSQL", 0) @@ -268,27 +313,15 @@ local function query(sql, values) return result end -local function array_values(key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for i = 1, #value do - if type(value[i]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[i] - end - else invalid(key .. " must be a string or repeated string parameter") end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function badge_award_filter_values(key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique + end) end local function subject_values() @@ -364,22 +397,6 @@ local function add_subject_filter(where, values, subjects) else where[#where + 1] = "(" .. table.concat(clauses, " OR ") .. ")" end end -local function decode_badge_award_cursor(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_badge_award_uri(value.u) then invalid("cursor is malformed") end - return value -end - local function recipient_did_expression() local subject = "award.record::jsonb->'subject'" return "CASE WHEN jsonb_typeof(" .. subject .. ") = 'string' THEN award.record::jsonb->>'subject' " .. @@ -540,15 +557,15 @@ local function handle_list_badge_awards() authors = true, badgeUris = true, badgeTypes = true, subjects = true, responses = true, sortDirection = true, limit = true, cursor = true, includeTotal = true, }) - local authors = array_values("authors", valid_did, "valid DIDs") - local badge_uris = array_values("badgeUris", valid_badge_definition_uri, "badge-definition AT-URIs") - local badge_types = array_values("badgeTypes", nil, nil, 100) + local authors = badge_award_filter_values("authors", valid_did, "valid DIDs") + local badge_uris = badge_award_filter_values("badgeUris", valid_badge_definition_uri, "badge-definition AT-URIs") + local badge_types = badge_award_filter_values("badgeTypes", nil, nil, 100) local subjects = subject_values() - local responses = array_values("responses", function(value) return RESPONSE_STATUSES[value] == true end, + local responses = badge_award_filter_values("responses", function(value) return RESPONSE_STATUSES[value] == true end, "accepted, rejected, or unanswered statuses") local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_badge_award_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_badge_award_uri) local include_total = parse_include_total(params) local views, next_cursor, total_count = list_badge_awards(authors, badge_uris, badge_types, subjects, responses, limit, cursor, direction, include_total) diff --git a/happyview-modules/lua/endpoints/listBadgeDefinitions.lua b/happyview-modules/lua/endpoints/listBadgeDefinitions.lua index 67c56d49..990a1b82 100644 --- a/happyview-modules/lua/endpoints/listBadgeDefinitions.lua +++ b/happyview-modules/lua/endpoints/listBadgeDefinitions.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -232,27 +275,15 @@ local function query(sql, values) return result end -local function badge_definition_array(params, key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for i = 1, #value do - if type(value[i]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[i] - end - else invalid(key .. " must be a string or repeated string parameter") end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function badge_definition_filter_values(params, key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique + end) end local function add_badge_definition_filter(where, values, column, items) @@ -266,24 +297,6 @@ local function add_badge_definition_filter(where, values, column, items) where[#where + 1] = column .. " IN (" .. table.concat(placeholders, ",") .. ")" end -local function decode_badge_definition_cursor(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_badge_definition_uri(value.u) then - invalid("cursor is malformed") - end - return value -end - local function list_badge_definitions(authors, badge_types, limit, cursor, direction) if db.backend() ~= "postgres" then error("BadgeDefinitionQueryFailed: badge definition API requires PostgreSQL", 0) @@ -328,11 +341,11 @@ end local function handle_list_badge_definitions() keys_only(params, { authors = true, badgeTypes = true, limit = true, cursor = true, sortDirection = true }) - local authors = badge_definition_array(params, "authors", valid_did, "valid DIDs") - local badge_types = badge_definition_array(params, "badgeTypes", nil, nil, 100) + local authors = badge_definition_filter_values(params, "authors", valid_did, "valid DIDs") + local badge_types = badge_definition_filter_values(params, "badgeTypes", nil, nil, 100) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_badge_definition_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_badge_definition_uri) local views, next_cursor = list_badge_definitions(authors, badge_types, limit, cursor, direction) local response = { badgeDefinitions = toarray(views) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/listBadgeResponses.lua b/happyview-modules/lua/endpoints/listBadgeResponses.lua index 6efdf8a7..44129e49 100644 --- a/happyview-modules/lua/endpoints/listBadgeResponses.lua +++ b/happyview-modules/lua/endpoints/listBadgeResponses.lua @@ -239,22 +239,6 @@ local function query(sql, values) return result end -local function decode_badge_response_cursor(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_badge_response_uri(value.u) then invalid("cursor is malformed") end - return value -end - local function list_badge_responses(badge_award, limit, cursor, direction) local where, values = { "response.collection = $1" }, { RESPONSE } if badge_award then @@ -314,7 +298,7 @@ local function handle_list_badge_responses() end local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_badge_response_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_badge_response_uri) local views, next_cursor = list_badge_responses(badge_award, limit, cursor, direction) local result = { badgeResponses = toarray(views) } if next_cursor then result.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/listCollections.lua b/happyview-modules/lua/endpoints/listCollections.lua index 72965e98..8f48cfb9 100644 --- a/happyview-modules/lua/endpoints/listCollections.lua +++ b/happyview-modules/lua/endpoints/listCollections.lua @@ -315,6 +315,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function parse_list_limit(params) local limit_value = scalar(params, "limit") if limit_value and not limit_value:match("^%d+$") then invalid("limit must be an integer from 1 through 100") end @@ -379,18 +422,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local function parse_include_total(values) @@ -403,33 +451,10 @@ local function parse_include_total(values) invalid("includeTotal must be true or false") end -local function collection_array(key, kind) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function collection_filter_values(key, kind) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if kind == "did" and not valid_did(item) then invalid("each authors value must be a valid DID; resolve handles to DIDs first") elseif kind == "collectionUri" then @@ -449,12 +474,7 @@ local function collection_array(key, kind) elseif kind == "type" and #item > 64 then invalid("types entries must be at most 64 UTF-8 bytes") end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function collection_bind_values(values, items) @@ -589,7 +609,7 @@ local function collection_list_response(search_enabled) if search_enabled then allowed.search = true else allowed.includeTotal = true end keys_only(params, allowed, "unknown query parameter: ") - local authors = collection_array("authors", "did") + local authors = collection_filter_values("authors", "did") local has_organization_record = scalar_or_boolean(params, "hasOrganizationRecord") if has_organization_record ~= nil then if has_organization_record == "true" then @@ -600,10 +620,10 @@ local function collection_list_response(search_enabled) invalid("hasOrganizationRecord must be true or false") end end - local types = collection_array("types", "type") - local uris = collection_array("uris", "collectionUri") - local item_uris = collection_array("itemUris", "recordUri") - local tag_uris = collection_array("tagUris", "tagUri") + local types = collection_filter_values("types", "type") + local uris = collection_filter_values("uris", "collectionUri") + local item_uris = collection_filter_values("itemUris", "recordUri") + local tag_uris = collection_filter_values("tagUris", "tagUri") local search if search_enabled then search = scalar(params, "search") diff --git a/happyview-modules/lua/endpoints/listContributions.lua b/happyview-modules/lua/endpoints/listContributions.lua index 4f97620b..ee13b451 100644 --- a/happyview-modules/lua/endpoints/listContributions.lua +++ b/happyview-modules/lua/endpoints/listContributions.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -229,54 +272,31 @@ local function contribution_view(row) return view end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local function contribution_authors() - local value = params.authors - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid("authors must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid("authors must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid("authors entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid("authors must be a string or repeated string parameter") - end - if #supplied > 100 then invalid("authors accepts at most 100 values") end - - local authors, seen = {}, {} - for _, did in ipairs(supplied) do + local supplied = query_string_values(params, "authors") + if not supplied then return nil end + return unique_query_values(supplied, function(did) if not valid_did(did) then invalid("each authors value must be a valid DID; resolve handles to DIDs first") end - if not seen[did] then - seen[did] = true - authors[#authors + 1] = did - end - end - return authors + end) end local function contribution_sort_key() diff --git a/happyview-modules/lua/endpoints/listContributorInformation.lua b/happyview-modules/lua/endpoints/listContributorInformation.lua index c275b9e1..47e58caf 100644 --- a/happyview-modules/lua/endpoints/listContributorInformation.lua +++ b/happyview-modules/lua/endpoints/listContributorInformation.lua @@ -28,6 +28,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_did(value) if type(value) ~= "string" or #value > 2048 then return false end local method, specific = value:match("^did:([a-z]+):(.+)$") @@ -210,18 +253,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" @@ -251,42 +299,14 @@ local function contributor_information_query(sql, values) return result end -local function contributor_information_array(params, key, validate, description) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function contributor_information_filter_values(params, key, validate, description) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description .. "; resolve handles to DIDs first") end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function preserve_contributor_author_timestamps(author) @@ -352,7 +372,7 @@ function handle() limit = true, cursor = true, }) - local authors = contributor_information_array(params, "authors", valid_did, "valid DIDs") + local authors = contributor_information_filter_values(params, "authors", valid_did, "valid DIDs") local limit = parse_list_limit(params) local direction = parse_sort_direction(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, contributor_information_uri) diff --git a/happyview-modules/lua/endpoints/listEvaluations.lua b/happyview-modules/lua/endpoints/listEvaluations.lua index 4e090730..3260441a 100644 --- a/happyview-modules/lua/endpoints/listEvaluations.lua +++ b/happyview-modules/lua/endpoints/listEvaluations.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -298,18 +341,23 @@ local function valid_nsid(value) return #name <= 63 and name:match("^[A-Za-z][A-Za-z0-9]*$") ~= nil end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" @@ -327,33 +375,10 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end -local function evaluation_array(key, format) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function evaluation_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") elseif format == "at-uri" then @@ -362,12 +387,7 @@ local function evaluation_array(key, format) invalid("each " .. key .. " value must be a full AT-URI with a DID authority and valid collection NSID") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function bind_evaluation_values(values, items) @@ -474,9 +494,9 @@ local function list_evaluations() cursor = true, }) - local authors = evaluation_array("authors", "did") - local evaluators = evaluation_array("evaluators", "did") - local subjects = evaluation_array("subjects", "at-uri") + local authors = evaluation_filter_values("authors", "did") + local evaluators = evaluation_filter_values("evaluators", "did") + local subjects = evaluation_filter_values("subjects", "at-uri") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, EVALUATION) diff --git a/happyview-modules/lua/endpoints/listEvmLinks.lua b/happyview-modules/lua/endpoints/listEvmLinks.lua index eb58917d..22b84884 100644 --- a/happyview-modules/lua/endpoints/listEvmLinks.lua +++ b/happyview-modules/lua/endpoints/listEvmLinks.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -251,34 +294,15 @@ local function valid_evm_address(value) return #value == 42 and value:match("^0x%x+$") ~= nil end -local function array_values(key, validate, description, normalize) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then - values[1] = value - elseif type(value) == "table" then - for index = 1, #value do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for index, item in ipairs(values) do +local function evm_link_filter_values(key, validate, description, normalize) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item, index) if not validate(item) then invalid(key .. "[" .. index .. "] must be " .. description) end - local normalized = normalize and normalize(item) or item - if not seen[normalized] then - seen[normalized] = true - unique[#unique + 1] = normalized - end - end - return unique + return normalize and normalize(item) or item + end) end local function add_filter(where, values, expression, items) @@ -295,26 +319,6 @@ local function add_filter(where, values, expression, items) where[#where + 1] = expression .. " IN (" .. table.concat(placeholders, ",") .. ")" end -local function decode_evm_link_cursor(token, direction) - if not token then return nil end - if #token == 0 or #token % 2 ~= 0 or token:find("[^0-9a-f]") then - invalid("cursor is malformed") - end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_evm_link_uri(value.u) then - invalid("cursor is malformed") - end - return value -end - local function list_evm_links(actors, addresses, limit, cursor, direction) local where, values = { "link.collection = $1" }, { EVMLINK } add_filter(where, values, "link.did", actors) @@ -368,11 +372,11 @@ function handle() limit = true, cursor = true, }) - local actors = array_values("actors", valid_did, "valid DIDs") - local addresses = array_values("addresses", valid_evm_address, "a 0x-prefixed 40-digit hexadecimal EVM address", string.lower) + local actors = evm_link_filter_values("actors", valid_did, "valid DIDs") + local addresses = evm_link_filter_values("addresses", valid_evm_address, "a 0x-prefixed 40-digit hexadecimal EVM address", string.lower) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_evm_link_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_evm_link_uri) local views, next_cursor = list_evm_links(actors, addresses, limit, cursor, direction) local response = { evmLinks = toarray(views) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/listFeatures.lua b/happyview-modules/lua/endpoints/listFeatures.lua index 92d7e8ab..e945a527 100644 --- a/happyview-modules/lua/endpoints/listFeatures.lua +++ b/happyview-modules/lua/endpoints/listFeatures.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -144,18 +187,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local FEATURE_COLLECTION = "org.hypercerts.entity.feature" @@ -255,42 +303,15 @@ end local FEATURE_VIEW_TYPE = "org.hypercerts.entity.defs#featureView" -local function feature_array(params, key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then - values[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated string query parameters") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated string query parameters") end - for index = 1, #value do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function feature_filter_values(params, key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function feature_add_types(where, values, binds) @@ -318,26 +339,6 @@ local function feature_parse_organization_filter(params) invalid("hasOrganizationRecord must be true or false") end -local function feature_cursor_decode(token, direction) - if token == nil then return nil end - if type(token) ~= "string" or #token > 32768 or #token % 2 ~= 0 or token:find("[^0-9a-f]") then - invalid("cursor is malformed") - end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not feature_valid_uri(value.u) or not valid_datetime(value.t) then - invalid("cursor is malformed") - end - return value -end - local function feature_query_rows(sql, binds) if db.backend() ~= "postgres" then error("FeatureQueryFailed: feature API requires PostgreSQL", 0) end local ok, rows = pcall(db.raw, sql, binds) @@ -401,14 +402,14 @@ local function list_features() limit = true, cursor = true, }) - local authors = feature_array(params, "authors", valid_did, "valid DIDs") - local types = feature_array(params, "types", nil, nil, 64) + local authors = feature_filter_values(params, "authors", valid_did, "valid DIDs") + local types = feature_filter_values(params, "types", nil, nil, 64) local has_organization_record = feature_parse_organization_filter(params) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) local cursor_value = params.cursor if cursor_value ~= nil and type(cursor_value) ~= "string" then invalid("cursor must occur once as a string") end - local cursor = feature_cursor_decode(cursor_value, direction) + local cursor = decode_record_cursor(cursor_value, direction, feature_valid_uri) local rows = feature_list_rows({ authors = authors, hasOrganizationRecord = has_organization_record, diff --git a/happyview-modules/lua/endpoints/listLocations.lua b/happyview-modules/lua/endpoints/listLocations.lua index a71d50c2..d49515e1 100644 --- a/happyview-modules/lua/endpoints/listLocations.lua +++ b/happyview-modules/lua/endpoints/listLocations.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -240,28 +283,16 @@ local function hydrate(views) hydrate_actor_views(authors, query) end -local function array(params, key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for i = 1, #value do - if type(value[i]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[i] - end - else invalid(key .. " must be a string or repeated string parameter") end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function location_filter_values(params, key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique + end) end -local function add_in(where, params, column, values) +local function add_optional_in(where, params, column, values) if not values then return end if #values == 0 then where[#where + 1] = "FALSE"; return end local placeholders = {} @@ -272,28 +303,12 @@ local function add_in(where, params, column, values) where[#where + 1] = column .. " IN (" .. table.concat(placeholders, ",") .. ")" end -local function cursor_decode(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_location_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value -end - local function query_locations(filters, limit, cursor, direction) if db.backend() ~= "postgres" then error("LocationQueryFailed: location API requires PostgreSQL", 0) end local where, binds = { "collection = $1" }, { COLLECTION } - add_in(where, binds, "did", filters.authors) - add_in(where, binds, "uri", filters.uris) - add_in(where, binds, "(record::jsonb)->>'locationType'", filters.locationTypes) + add_optional_in(where, binds, "did", filters.authors) + add_optional_in(where, binds, "uri", filters.uris) + add_optional_in(where, binds, "(record::jsonb)->>'locationType'", filters.locationTypes) if cursor then binds[#binds + 1] = cursor.t local time = "$" .. #binds @@ -321,12 +336,12 @@ end local function list_locations() keys_only(params, { authors = true, uris = true, locationTypes = true, limit = true, cursor = true, sortDirection = true }) - local authors = array(params, "authors", valid_did, "valid DIDs") - local uris = array(params, "uris", valid_location_uri, "full app.certified.location AT-URIs with DID authorities") - local types = array(params, "locationTypes", nil, nil, 20) + local authors = location_filter_values(params, "authors", valid_did, "valid DIDs") + local uris = location_filter_values(params, "uris", valid_location_uri, "full app.certified.location AT-URIs with DID authorities") + local types = location_filter_values(params, "locationTypes", nil, nil, 20) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_location_uri) local views, next_cursor = query_locations({ authors = authors, uris = uris, locationTypes = types }, limit, cursor, direction) local response = { locations = toarray(views) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/listMeasurements.lua b/happyview-modules/lua/endpoints/listMeasurements.lua index be6eef7c..e43de774 100644 --- a/happyview-modules/lua/endpoints/listMeasurements.lua +++ b/happyview-modules/lua/endpoints/listMeasurements.lua @@ -28,6 +28,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_did(value) if type(value) ~= "string" or #value > 2048 then return false end local method, specific = value:match("^did:([a-z]+):(.+)$") @@ -257,18 +300,23 @@ local function valid_nsid(value) return #name <= 63 and name:match("^[A-Za-z][A-Za-z0-9]*$") ~= nil end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" @@ -286,33 +334,10 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end -local function measurement_array(key, format) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function measurement_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID") elseif format == "at-uri" then @@ -321,21 +346,7 @@ local function measurement_array(key, format) invalid("each " .. key .. " value must be a full AT-URI with a DID authority and valid collection NSID") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique -end - -local function bind_values(values, items) - local placeholders = {} - for _, item in ipairs(items) do - values[#values + 1] = item - placeholders[#placeholders + 1] = "$" .. #values - end - return placeholders + end) end local function measurement_list_query(authors, subjects, limit, cursor, direction) @@ -398,8 +409,8 @@ function handle() cursor = true, }) - local authors = measurement_array("authors", "did") - local subjects = measurement_array("subjects", "at-uri") + local authors = measurement_filter_values("authors", "did") + local subjects = measurement_filter_values("subjects", "at-uri") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, MEASUREMENT) diff --git a/happyview-modules/lua/endpoints/listOrganizations.lua b/happyview-modules/lua/endpoints/listOrganizations.lua index 8a252893..77144203 100644 --- a/happyview-modules/lua/endpoints/listOrganizations.lua +++ b/happyview-modules/lua/endpoints/listOrganizations.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -288,18 +331,23 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end -- Hydrates page rows through the shared actor lookup, keeping this API's error @@ -316,41 +364,15 @@ local function valid_organization_uri(value) return valid and collection == ORGANIZATION and value:sub(-5) == "/self" end -local function array(params, key) - local value = params[key] - if value == nil then return nil end - local values, occurrences = {}, 0 - if type(value) == "string" then - values[1] = value - elseif type(value) == "table" then - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - occurrences = occurrences + 1 - end - if occurrences ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, occurrences do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function organization_filter_values(params, key) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if key == "actors" and not valid_did(item) then invalid("each actors value must be a valid DID") end if key == "organizationTypes" and #item > 128 then invalid("each organizationTypes value must be at most 128 characters") end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function add_organization_types(where, values, organization_types) @@ -367,22 +389,6 @@ local function add_organization_types(where, values, organization_types) ") AS organization_type(value) WHERE organization_type.value IN (" .. table.concat(placeholders, ", ") .. "))" end -local function cursor_decode(token, direction) - if token == nil then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_organization_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value -end - local function query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local where, values = { "organization.collection = $1", "organization.rkey = 'self'" }, { ORGANIZATION } if actors then add_in(where, values, "organization.did", actors) end @@ -447,8 +453,8 @@ local function organizations_response(search_enabled) keys_only(params, allowed) local actors - if search_enabled then actors = array(params, "actors") end - local organization_types = array(params, "organizationTypes") + if search_enabled then actors = organization_filter_values(params, "actors") end + local organization_types = organization_filter_values(params, "organizationTypes") local visibility = scalar(params, "visibility") local search if search_enabled then @@ -461,7 +467,7 @@ local function organizations_response(search_enabled) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_organization_uri) local actors_result, next_cursor = query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local response = { actors = toarray(actors_result) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/listProfiles.lua b/happyview-modules/lua/endpoints/listProfiles.lua index bfa7168e..0e08f602 100644 --- a/happyview-modules/lua/endpoints/listProfiles.lua +++ b/happyview-modules/lua/endpoints/listProfiles.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -194,18 +237,23 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local function valid_profile_uri(value) @@ -214,42 +262,12 @@ local function valid_profile_uri(value) return valid and collection == PROFILE and value:sub(-5) == "/self" end -local function array(params, key) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for index = 1, #value do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function profile_filter_values(params, key) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if not valid_did(item) then invalid("each " .. key .. " value must be a valid DID") end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique -end - -local function cursor_decode(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_profile_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value + end) end local function query_profiles(actors, search, limit, cursor, direction) @@ -299,7 +317,7 @@ local function profiles_response(search_enabled) end keys_only(params, allowed) local actors - if search_enabled then actors = array(params, "actors") end + if search_enabled then actors = profile_filter_values(params, "actors") end local search if search_enabled then search = scalar(params, "search") @@ -311,7 +329,7 @@ local function profiles_response(search_enabled) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_profile_uri) local profiles, next_cursor = query_profiles(actors, search, limit, cursor, direction) local response = { profiles = toarray(profiles) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/listReceipts.lua b/happyview-modules/lua/endpoints/listReceipts.lua index dfee9c38..5db326cd 100644 --- a/happyview-modules/lua/endpoints/listReceipts.lua +++ b/happyview-modules/lua/endpoints/listReceipts.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -249,18 +292,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" @@ -294,32 +342,10 @@ local function valid_funding_record_uri(value) return true, collection end -local function funding_receipt_array(key, format) - local value = params[key] - if value == nil then return nil end - - local supplied, occurrences = {}, 0 - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - occurrences = occurrences + 1 - end - if occurrences ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, occurrences do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function funding_receipt_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid(key .. " entry " .. string.format("%q", item) .. " must be a valid DID") elseif format == "receiptUri" then @@ -341,13 +367,7 @@ local function funding_receipt_array(key, format) " must be a valid DID or full record AT-URI; resolve handles to DIDs before querying") end end - - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function bind_funding_receipt_values(values, items) @@ -459,12 +479,12 @@ local function funding_receipts_response() cursor = true, }) - local authors = funding_receipt_array("authors", "did") - local uris = funding_receipt_array("uris", "receiptUri") - local from_values = funding_receipt_array("from", "party") - local to_values = funding_receipt_array("to", "party") - local for_uris = funding_receipt_array("forUris", "atUri") - local transaction_ids = funding_receipt_array("transactionIds") + local authors = funding_receipt_filter_values("authors", "did") + local uris = funding_receipt_filter_values("uris", "receiptUri") + local from_values = funding_receipt_filter_values("from", "party") + local to_values = funding_receipt_filter_values("to", "party") + local for_uris = funding_receipt_filter_values("forUris", "atUri") + local transaction_ids = funding_receipt_filter_values("transactionIds") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) diff --git a/happyview-modules/lua/endpoints/listRights.lua b/happyview-modules/lua/endpoints/listRights.lua index 173b021a..7bd4cd95 100644 --- a/happyview-modules/lua/endpoints/listRights.lua +++ b/happyview-modules/lua/endpoints/listRights.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -202,18 +245,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local CREATED_AT_SORT_PATTERN = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$" @@ -240,40 +288,6 @@ local function rights_list_run_query(sql, values) return result end -local function rights_list_array(value) - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid("authors must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid("authors must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid("authors entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid("authors must be a string or repeated string parameter") - end - if #supplied > 100 then invalid("authors accepts at most 100 values") end - - local unique, seen = {}, {} - for _, did in ipairs(supplied) do - if not valid_did(did) then invalid("each authors value must be a valid DID") end - if not seen[did] then - seen[did] = true - unique[#unique + 1] = did - end - end - return unique -end - local function rights_list_query(authors, limit, cursor, direction) local where, values = { "rights.collection = $1" }, { RIGHTS } @@ -320,7 +334,10 @@ end local function rights_list_response() keys_only(params, { authors = true, sortDirection = true, limit = true, cursor = true }) - local authors = rights_list_array(params.authors) + local authors = query_string_values(params, "authors") + authors = authors and unique_query_values(authors, function(did) + if not valid_did(did) then invalid("each authors value must be a valid DID") end + end) local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, RIGHTS) diff --git a/happyview-modules/lua/endpoints/listVocabTags.lua b/happyview-modules/lua/endpoints/listVocabTags.lua index 2d1181ee..73cb7646 100644 --- a/happyview-modules/lua/endpoints/listVocabTags.lua +++ b/happyview-modules/lua/endpoints/listVocabTags.lua @@ -218,6 +218,9 @@ local function query(sql, values) return result end +-- Not query_string_values: its shape error is "authors must be repeated string values" +-- (the shared parser says "must use repeated query values"), and the result is sorted +-- because the author list is part of the cursor signature. local function parse_authors(value) if value == nil then return nil end local supplied = {} diff --git a/happyview-modules/lua/endpoints/listWorkscopeTags.lua b/happyview-modules/lua/endpoints/listWorkscopeTags.lua index 77ad17f5..1a629455 100644 --- a/happyview-modules/lua/endpoints/listWorkscopeTags.lua +++ b/happyview-modules/lua/endpoints/listWorkscopeTags.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -227,61 +270,38 @@ local function workscope_tag_view(row) } end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end -local function workscope_tag_array(key) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, did in ipairs(supplied) do +local function workscope_tag_filter_values(key) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(did) if not valid_did(did) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") end - if not seen[did] then - seen[did] = true - unique[#unique + 1] = did - end - end - return unique + end) end local function workscope_tag_list() keys_only(params, { authors = true, sortDirection = true, limit = true, cursor = true }) - local authors = workscope_tag_array("authors") + local authors = workscope_tag_filter_values("authors") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, WORKSCOPE_TAG) diff --git a/happyview-modules/lua/endpoints/searchActivities.lua b/happyview-modules/lua/endpoints/searchActivities.lua index 635f0ec2..3166cd33 100644 --- a/happyview-modules/lua/endpoints/searchActivities.lua +++ b/happyview-modules/lua/endpoints/searchActivities.lua @@ -234,6 +234,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local ACTIVITY = "org.hypercerts.claim.activity" local function query(sql, values) @@ -356,18 +399,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local function parse_include_total(values) @@ -380,32 +428,10 @@ local function parse_include_total(values) invalid("includeTotal must be true or false") end -local function activity_array(key, format) - local value = params[key] - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function activity_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") elseif format == "activityUri" then @@ -414,21 +440,7 @@ local function activity_array(key, format) invalid("each uris value must be a full org.hypercerts.claim.activity AT-URI with a DID authority") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique -end - -local function bind_values(values, items) - local placeholders = {} - for _, item in ipairs(items) do - values[#values + 1] = item - placeholders[#placeholders + 1] = "$" .. #values - end - return placeholders + end) end local function activity_contributor_match(values, dids) @@ -543,7 +555,7 @@ local function activity_list_response(search_enabled) if search_enabled then allowed.search = true else allowed.includeTotal = true end keys_only(params, allowed, "unknown query parameter: ") - local authors = activity_array("authors", "did") + local authors = activity_filter_values("authors", "did") local has_organization_record = scalar_or_boolean(params, "hasOrganizationRecord") if has_organization_record ~= nil then if has_organization_record == "true" then @@ -554,9 +566,9 @@ local function activity_list_response(search_enabled) invalid("hasOrganizationRecord must be true or false") end end - local contributors = activity_array("contributors", "did") - local involved_actors = activity_array("involvedActors", "did") - local uris = activity_array("uris", "activityUri") + local contributors = activity_filter_values("contributors", "did") + local involved_actors = activity_filter_values("involvedActors", "did") + local uris = activity_filter_values("uris", "activityUri") local search if search_enabled then search = scalar(params, "search") diff --git a/happyview-modules/lua/endpoints/searchBadgeDefinitions.lua b/happyview-modules/lua/endpoints/searchBadgeDefinitions.lua index aeb6ff47..7468cb66 100644 --- a/happyview-modules/lua/endpoints/searchBadgeDefinitions.lua +++ b/happyview-modules/lua/endpoints/searchBadgeDefinitions.lua @@ -28,6 +28,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_did(value) if type(value) ~= "string" or #value > 2048 then return false end local method, specific = value:match("^did:([a-z]+):(.+)$") @@ -235,27 +278,15 @@ local function query(sql, values) return result end -local function badge_definition_array(key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for i = 1, #value do - if type(value[i]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[i] - end - else invalid(key .. " must be a string or repeated string parameter") end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function badge_definition_filter_values(key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique + end) end local function add_badge_definition_filter(where, values, column, items) @@ -269,24 +300,6 @@ local function add_badge_definition_filter(where, values, column, items) where[#where + 1] = column .. " IN (" .. table.concat(placeholders, ",") .. ")" end -local function decode_badge_definition_cursor(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_badge_definition_uri(value.u) then - invalid("cursor is malformed") - end - return value -end - local function query_badge_definitions(authors, badge_types, search, limit, cursor, direction) local where, values = { "collection = $1" }, { COLLECTION } add_badge_definition_filter(where, values, "did", authors) @@ -349,11 +362,11 @@ local function handle_search_badge_definitions() if search == nil then invalid("search is required") end search = search:match("^%s*(.-)%s*$") if search == "" then search = nil end - local authors = badge_definition_array("authors", valid_did, "valid DIDs") - local badge_types = badge_definition_array("badgeTypes", nil, nil, 100) + local authors = badge_definition_filter_values("authors", valid_did, "valid DIDs") + local badge_types = badge_definition_filter_values("badgeTypes", nil, nil, 100) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_badge_definition_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_badge_definition_uri) local views, next_cursor = query_badge_definitions(authors, badge_types, search, limit, cursor, direction) local response = { badgeDefinitions = toarray(views) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/searchCollections.lua b/happyview-modules/lua/endpoints/searchCollections.lua index 00f64ca2..921de540 100644 --- a/happyview-modules/lua/endpoints/searchCollections.lua +++ b/happyview-modules/lua/endpoints/searchCollections.lua @@ -315,6 +315,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function parse_list_limit(params) local limit_value = scalar(params, "limit") if limit_value and not limit_value:match("^%d+$") then invalid("limit must be an integer from 1 through 100") end @@ -379,18 +422,23 @@ local function parse_sort_direction(params) return direction end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local function parse_include_total(values) @@ -403,33 +451,10 @@ local function parse_include_total(values) invalid("includeTotal must be true or false") end -local function collection_array(key, kind) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function collection_filter_values(key, kind) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if kind == "did" and not valid_did(item) then invalid("each authors value must be a valid DID; resolve handles to DIDs first") elseif kind == "collectionUri" then @@ -449,12 +474,7 @@ local function collection_array(key, kind) elseif kind == "type" and #item > 64 then invalid("types entries must be at most 64 UTF-8 bytes") end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function collection_bind_values(values, items) @@ -589,7 +609,7 @@ local function collection_list_response(search_enabled) if search_enabled then allowed.search = true else allowed.includeTotal = true end keys_only(params, allowed, "unknown query parameter: ") - local authors = collection_array("authors", "did") + local authors = collection_filter_values("authors", "did") local has_organization_record = scalar_or_boolean(params, "hasOrganizationRecord") if has_organization_record ~= nil then if has_organization_record == "true" then @@ -600,10 +620,10 @@ local function collection_list_response(search_enabled) invalid("hasOrganizationRecord must be true or false") end end - local types = collection_array("types", "type") - local uris = collection_array("uris", "collectionUri") - local item_uris = collection_array("itemUris", "recordUri") - local tag_uris = collection_array("tagUris", "tagUri") + local types = collection_filter_values("types", "type") + local uris = collection_filter_values("uris", "collectionUri") + local item_uris = collection_filter_values("itemUris", "recordUri") + local tag_uris = collection_filter_values("tagUris", "tagUri") local search if search_enabled then search = scalar(params, "search") diff --git a/happyview-modules/lua/endpoints/searchOrganizations.lua b/happyview-modules/lua/endpoints/searchOrganizations.lua index 123c742f..303e8594 100644 --- a/happyview-modules/lua/endpoints/searchOrganizations.lua +++ b/happyview-modules/lua/endpoints/searchOrganizations.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -288,18 +331,23 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end -- Hydrates page rows through the shared actor lookup, keeping this API's error @@ -316,41 +364,15 @@ local function valid_organization_uri(value) return valid and collection == ORGANIZATION and value:sub(-5) == "/self" end -local function array(params, key) - local value = params[key] - if value == nil then return nil end - local values, occurrences = {}, 0 - if type(value) == "string" then - values[1] = value - elseif type(value) == "table" then - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - occurrences = occurrences + 1 - end - if occurrences ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, occurrences do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function organization_filter_values(params, key) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if key == "actors" and not valid_did(item) then invalid("each actors value must be a valid DID") end if key == "organizationTypes" and #item > 128 then invalid("each organizationTypes value must be at most 128 characters") end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function add_organization_types(where, values, organization_types) @@ -367,22 +389,6 @@ local function add_organization_types(where, values, organization_types) ") AS organization_type(value) WHERE organization_type.value IN (" .. table.concat(placeholders, ", ") .. "))" end -local function cursor_decode(token, direction) - if token == nil then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_organization_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value -end - local function query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local where, values = { "organization.collection = $1", "organization.rkey = 'self'" }, { ORGANIZATION } if actors then add_in(where, values, "organization.did", actors) end @@ -447,8 +453,8 @@ local function organizations_response(search_enabled) keys_only(params, allowed) local actors - if search_enabled then actors = array(params, "actors") end - local organization_types = array(params, "organizationTypes") + if search_enabled then actors = organization_filter_values(params, "actors") end + local organization_types = organization_filter_values(params, "organizationTypes") local visibility = scalar(params, "visibility") local search if search_enabled then @@ -461,7 +467,7 @@ local function organizations_response(search_enabled) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_organization_uri) local actors_result, next_cursor = query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local response = { actors = toarray(actors_result) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/endpoints/searchProfiles.lua b/happyview-modules/lua/endpoints/searchProfiles.lua index fbe38300..ddd3ca79 100644 --- a/happyview-modules/lua/endpoints/searchProfiles.lua +++ b/happyview-modules/lua/endpoints/searchProfiles.lua @@ -36,6 +36,49 @@ local function scalar_or_boolean(values, key) end -- luacheck: pop +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end + local function valid_record_key(value) return #value >= 1 and #value <= 512 and value ~= "." and value ~= ".." and not value:find("[^%w_~%.:%-]") @@ -194,18 +237,23 @@ local function created_at_sort(alias) "::timestamptz, " .. created_at .. "::timestamptz) END" end +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end local function valid_profile_uri(value) @@ -214,42 +262,12 @@ local function valid_profile_uri(value) return valid and collection == PROFILE and value:sub(-5) == "/self" end -local function array(params, key) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for index = 1, #value do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function profile_filter_values(params, key) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if not valid_did(item) then invalid("each " .. key .. " value must be a valid DID") end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique -end - -local function cursor_decode(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_profile_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value + end) end local function query_profiles(actors, search, limit, cursor, direction) @@ -299,7 +317,7 @@ local function profiles_response(search_enabled) end keys_only(params, allowed) local actors - if search_enabled then actors = array(params, "actors") end + if search_enabled then actors = profile_filter_values(params, "actors") end local search if search_enabled then search = scalar(params, "search") @@ -311,7 +329,7 @@ local function profiles_response(search_enabled) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_profile_uri) local profiles, next_cursor = query_profiles(actors, search, limit, cursor, direction) local response = { profiles = toarray(profiles) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/shared/acknowledgementList.lua b/happyview-modules/lua/shared/acknowledgementList.lua index 53c72682..abb69d52 100644 --- a/happyview-modules/lua/shared/acknowledgementList.lua +++ b/happyview-modules/lua/shared/acknowledgementList.lua @@ -6,32 +6,10 @@ local function valid_cursor_timestamp(value) return valid_datetime(value) end -local function acknowledgement_array(key, format) - local value = params[key] - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function acknowledgement_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") elseif format == "at-uri" then @@ -40,12 +18,7 @@ local function acknowledgement_array(key, format) invalid("each " .. key .. " value must be a full AT-URI with a DID authority and valid collection NSID") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function acknowledgement_sort_expression() @@ -95,8 +68,8 @@ local function list_acknowledgements() limit = true, cursor = true, }) - local authors = acknowledgement_array("authors", "did") - local subjects = acknowledgement_array("subjects", "at-uri") + local authors = acknowledgement_filter_values("authors", "did") + local subjects = acknowledgement_filter_values("subjects", "at-uri") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, ACKNOWLEDGEMENT, valid_cursor_timestamp) diff --git a/happyview-modules/lua/shared/activityList.lua b/happyview-modules/lua/shared/activityList.lua index 54a01dab..b2846b54 100644 --- a/happyview-modules/lua/shared/activityList.lua +++ b/happyview-modules/lua/shared/activityList.lua @@ -1,29 +1,7 @@ -local function activity_array(key, format) - local value = params[key] - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function activity_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") elseif format == "activityUri" then @@ -32,21 +10,7 @@ local function activity_array(key, format) invalid("each uris value must be a full org.hypercerts.claim.activity AT-URI with a DID authority") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique -end - -local function bind_values(values, items) - local placeholders = {} - for _, item in ipairs(items) do - values[#values + 1] = item - placeholders[#placeholders + 1] = "$" .. #values - end - return placeholders + end) end local function activity_contributor_match(values, dids) @@ -161,7 +125,7 @@ local function activity_list_response(search_enabled) if search_enabled then allowed.search = true else allowed.includeTotal = true end keys_only(params, allowed, "unknown query parameter: ") - local authors = activity_array("authors", "did") + local authors = activity_filter_values("authors", "did") local has_organization_record = scalar_or_boolean(params, "hasOrganizationRecord") if has_organization_record ~= nil then if has_organization_record == "true" then @@ -172,9 +136,9 @@ local function activity_list_response(search_enabled) invalid("hasOrganizationRecord must be true or false") end end - local contributors = activity_array("contributors", "did") - local involved_actors = activity_array("involvedActors", "did") - local uris = activity_array("uris", "activityUri") + local contributors = activity_filter_values("contributors", "did") + local involved_actors = activity_filter_values("involvedActors", "did") + local uris = activity_filter_values("uris", "activityUri") local search if search_enabled then search = scalar(params, "search") diff --git a/happyview-modules/lua/shared/actorFollowList.lua b/happyview-modules/lua/shared/actorFollowList.lua index 329fe35e..4b35ea2e 100644 --- a/happyview-modules/lua/shared/actorFollowList.lua +++ b/happyview-modules/lua/shared/actorFollowList.lua @@ -1,24 +1,3 @@ -local function valid_follow_uri(value) - local valid, collection = valid_record_uri(value) - return valid and collection == FOLLOW -end - -local function cursor_decode(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_follow_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value -end - local function build_actor_follow_query(mode, actor, limit, cursor, direction) local filters, values = { "collection = $1", account_follow_filter_sql() }, { FOLLOW } values[#values + 1] = actor @@ -82,7 +61,7 @@ local function list_actor_follows(mode) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, FOLLOW) local views, next_cursor, total_count = query_actor_follows(mode, actor, limit, cursor, direction) local response = { [mode] = toarray(views), totalCount = total_count } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/shared/attachmentList.lua b/happyview-modules/lua/shared/attachmentList.lua index 5cf9b229..83c6acba 100644 --- a/happyview-modules/lua/shared/attachmentList.lua +++ b/happyview-modules/lua/shared/attachmentList.lua @@ -1,36 +1,9 @@ -local function attachment_array(params, key, validate, description) - local value = params[key] - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function attachment_filter_values(params, key, validate, description) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function attachment_subject_filter(where, values, subjects) @@ -104,13 +77,13 @@ local function list_attachments() limit = true, cursor = true, }) - local authors = attachment_array(params, "authors", valid_did, "valid DIDs") - local uris = attachment_array(params, "uris", valid_attachment_uri, + local authors = attachment_filter_values(params, "authors", valid_did, "valid DIDs") + local uris = attachment_filter_values(params, "uris", valid_attachment_uri, "full org.hypercerts.context.attachment AT-URIs with DID authorities") - local subjects = attachment_array(params, "subjects", function(value) + local subjects = attachment_filter_values(params, "subjects", function(value) return valid_record_uri(value) end, "full AT-URIs with DID authorities") - local content_types = attachment_array(params, "contentTypes") + local content_types = attachment_filter_values(params, "contentTypes") local limit = parse_list_limit(params) local direction = parse_sort_direction(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_attachment_uri) diff --git a/happyview-modules/lua/shared/collectionList.lua b/happyview-modules/lua/shared/collectionList.lua index a4229712..6d9acb69 100644 --- a/happyview-modules/lua/shared/collectionList.lua +++ b/happyview-modules/lua/shared/collectionList.lua @@ -1,30 +1,7 @@ -local function collection_array(key, kind) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function collection_filter_values(key, kind) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if kind == "did" and not valid_did(item) then invalid("each authors value must be a valid DID; resolve handles to DIDs first") elseif kind == "collectionUri" then @@ -44,12 +21,7 @@ local function collection_array(key, kind) elseif kind == "type" and #item > 64 then invalid("types entries must be at most 64 UTF-8 bytes") end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function collection_bind_values(values, items) @@ -184,7 +156,7 @@ local function collection_list_response(search_enabled) if search_enabled then allowed.search = true else allowed.includeTotal = true end keys_only(params, allowed, "unknown query parameter: ") - local authors = collection_array("authors", "did") + local authors = collection_filter_values("authors", "did") local has_organization_record = scalar_or_boolean(params, "hasOrganizationRecord") if has_organization_record ~= nil then if has_organization_record == "true" then @@ -195,10 +167,10 @@ local function collection_list_response(search_enabled) invalid("hasOrganizationRecord must be true or false") end end - local types = collection_array("types", "type") - local uris = collection_array("uris", "collectionUri") - local item_uris = collection_array("itemUris", "recordUri") - local tag_uris = collection_array("tagUris", "tagUri") + local types = collection_filter_values("types", "type") + local uris = collection_filter_values("uris", "collectionUri") + local item_uris = collection_filter_values("itemUris", "recordUri") + local tag_uris = collection_filter_values("tagUris", "tagUri") local search if search_enabled then search = scalar(params, "search") diff --git a/happyview-modules/lua/shared/evaluationList.lua b/happyview-modules/lua/shared/evaluationList.lua index b46507c6..178f5a2b 100644 --- a/happyview-modules/lua/shared/evaluationList.lua +++ b/happyview-modules/lua/shared/evaluationList.lua @@ -1,30 +1,7 @@ -local function evaluation_array(key, format) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function evaluation_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") elseif format == "at-uri" then @@ -33,12 +10,7 @@ local function evaluation_array(key, format) invalid("each " .. key .. " value must be a full AT-URI with a DID authority and valid collection NSID") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function bind_evaluation_values(values, items) @@ -145,9 +117,9 @@ local function list_evaluations() cursor = true, }) - local authors = evaluation_array("authors", "did") - local evaluators = evaluation_array("evaluators", "did") - local subjects = evaluation_array("subjects", "at-uri") + local authors = evaluation_filter_values("authors", "did") + local evaluators = evaluation_filter_values("evaluators", "did") + local subjects = evaluation_filter_values("subjects", "at-uri") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, EVALUATION) diff --git a/happyview-modules/lua/shared/feedActorReactions.lua b/happyview-modules/lua/shared/feedActorReactions.lua index 3141a1d6..e52e5dc6 100644 --- a/happyview-modules/lua/shared/feedActorReactions.lua +++ b/happyview-modules/lua/shared/feedActorReactions.lua @@ -14,6 +14,8 @@ local function actor_reaction_sort_key() ", 'timestamptz') THEN (" .. created .. ")::timestamptz ELSE COALESCE(indexed_at::timestamptz, created_at::timestamptz) END" end +-- Not query_string_values: subjects is required, keeps duplicates in request order, and +-- reports the range as "subjects must contain 1 through 100 AT-URIs". local function feed_actor_reaction_subjects(actor, value) if value == nil then invalid("subjects is required") end diff --git a/happyview-modules/lua/shared/fundingReceiptList.lua b/happyview-modules/lua/shared/fundingReceiptList.lua index 03cd488c..0c996150 100644 --- a/happyview-modules/lua/shared/fundingReceiptList.lua +++ b/happyview-modules/lua/shared/fundingReceiptList.lua @@ -4,32 +4,10 @@ local function valid_funding_record_uri(value) return true, collection end -local function funding_receipt_array(key, format) - local value = params[key] - if value == nil then return nil end - - local supplied, occurrences = {}, 0 - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - occurrences = occurrences + 1 - end - if occurrences ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, occurrences do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function funding_receipt_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid(key .. " entry " .. string.format("%q", item) .. " must be a valid DID") elseif format == "receiptUri" then @@ -51,13 +29,7 @@ local function funding_receipt_array(key, format) " must be a valid DID or full record AT-URI; resolve handles to DIDs before querying") end end - - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function bind_funding_receipt_values(values, items) @@ -169,12 +141,12 @@ local function funding_receipts_response() cursor = true, }) - local authors = funding_receipt_array("authors", "did") - local uris = funding_receipt_array("uris", "receiptUri") - local from_values = funding_receipt_array("from", "party") - local to_values = funding_receipt_array("to", "party") - local for_uris = funding_receipt_array("forUris", "atUri") - local transaction_ids = funding_receipt_array("transactionIds") + local authors = funding_receipt_filter_values("authors", "did") + local uris = funding_receipt_filter_values("uris", "receiptUri") + local from_values = funding_receipt_filter_values("from", "party") + local to_values = funding_receipt_filter_values("to", "party") + local for_uris = funding_receipt_filter_values("forUris", "atUri") + local transaction_ids = funding_receipt_filter_values("transactionIds") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) diff --git a/happyview-modules/lua/shared/listWhere.lua b/happyview-modules/lua/shared/listWhere.lua index b5080271..3ccf25cf 100644 --- a/happyview-modules/lua/shared/listWhere.lua +++ b/happyview-modules/lua/shared/listWhere.lua @@ -1,13 +1,18 @@ +-- Appends each item to binds and returns its "$n" placeholders, in order. +local function bind_values(binds, items) + local placeholders = {} + for _, item in ipairs(items) do + binds[#binds + 1] = item + placeholders[#placeholders + 1] = "$" .. #binds + end + return placeholders +end + -- Adds `column IN ($n, ...)` to where, binding items; an empty list matches nothing. local function add_in(where, binds, column, items) if #items == 0 then where[#where + 1] = "FALSE" return end - local marks = {} - for _, item in ipairs(items) do - binds[#binds + 1] = item - marks[#marks + 1] = "$" .. #binds - end - where[#where + 1] = column .. " IN (" .. table.concat(marks, ", ") .. ")" + where[#where + 1] = column .. " IN (" .. table.concat(bind_values(binds, items), ", ") .. ")" end diff --git a/happyview-modules/lua/shared/organizationList.lua b/happyview-modules/lua/shared/organizationList.lua index 338f1625..e7893d7a 100644 --- a/happyview-modules/lua/shared/organizationList.lua +++ b/happyview-modules/lua/shared/organizationList.lua @@ -12,41 +12,15 @@ local function valid_organization_uri(value) return valid and collection == ORGANIZATION and value:sub(-5) == "/self" end -local function array(params, key) - local value = params[key] - if value == nil then return nil end - local values, occurrences = {}, 0 - if type(value) == "string" then - values[1] = value - elseif type(value) == "table" then - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - occurrences = occurrences + 1 - end - if occurrences ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, occurrences do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function organization_filter_values(params, key) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if key == "actors" and not valid_did(item) then invalid("each actors value must be a valid DID") end if key == "organizationTypes" and #item > 128 then invalid("each organizationTypes value must be at most 128 characters") end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function add_organization_types(where, values, organization_types) @@ -63,22 +37,6 @@ local function add_organization_types(where, values, organization_types) ") AS organization_type(value) WHERE organization_type.value IN (" .. table.concat(placeholders, ", ") .. "))" end -local function cursor_decode(token, direction) - if token == nil then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_organization_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value -end - local function query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local where, values = { "organization.collection = $1", "organization.rkey = 'self'" }, { ORGANIZATION } if actors then add_in(where, values, "organization.did", actors) end @@ -143,8 +101,8 @@ local function organizations_response(search_enabled) keys_only(params, allowed) local actors - if search_enabled then actors = array(params, "actors") end - local organization_types = array(params, "organizationTypes") + if search_enabled then actors = organization_filter_values(params, "actors") end + local organization_types = organization_filter_values(params, "organizationTypes") local visibility = scalar(params, "visibility") local search if search_enabled then @@ -157,7 +115,7 @@ local function organizations_response(search_enabled) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_organization_uri) local actors_result, next_cursor = query_organizations(actors, organization_types, visibility, search, limit, cursor, direction) local response = { actors = toarray(actors_result) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/shared/profileList.lua b/happyview-modules/lua/shared/profileList.lua index de57432a..0c243404 100644 --- a/happyview-modules/lua/shared/profileList.lua +++ b/happyview-modules/lua/shared/profileList.lua @@ -4,42 +4,12 @@ local function valid_profile_uri(value) return valid and collection == PROFILE and value:sub(-5) == "/self" end -local function array(params, key) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for index = 1, #value do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function profile_filter_values(params, key) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if not valid_did(item) then invalid("each " .. key .. " value must be a valid DID") end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique -end - -local function cursor_decode(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_profile_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value + end) end local function query_profiles(actors, search, limit, cursor, direction) @@ -89,7 +59,7 @@ local function profiles_response(search_enabled) end keys_only(params, allowed) local actors - if search_enabled then actors = array(params, "actors") end + if search_enabled then actors = profile_filter_values(params, "actors") end local search if search_enabled then search = scalar(params, "search") @@ -101,7 +71,7 @@ local function profiles_response(search_enabled) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_profile_uri) local profiles, next_cursor = query_profiles(actors, search, limit, cursor, direction) local response = { profiles = toarray(profiles) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/shared/queryArray.lua b/happyview-modules/lua/shared/queryArray.lua new file mode 100644 index 00000000..0c34a946 --- /dev/null +++ b/happyview-modules/lua/shared/queryArray.lua @@ -0,0 +1,42 @@ +-- Reads a repeated query parameter (?key=a&key=b) as a list of strings, or nil when absent. +-- A single value counts as a list of one. Rejects non-string entries, keyed or sparse +-- tables and more than 100 values. Item rules stay with the caller so each endpoint keeps +-- its own error messages; see unique_query_values. +local function query_string_values(params, key) + local value = params[key] + if value == nil then return nil end + if type(value) == "string" then return { value } end + if type(value) ~= "table" then + invalid(key .. " must be a string or repeated string parameter") + end + local count = 0 + for index in pairs(value) do + if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then + invalid(key .. " must use repeated query values") + end + count = count + 1 + end + if count ~= #value then invalid(key .. " must use repeated query values") end + local values = {} + for index = 1, count do + if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end + values[index] = value[index] + end + if #values > 100 then invalid(key .. " accepts at most 100 values") end + return values +end + +-- Runs check(item, index) on every value in order, then returns the distinct results in +-- first-seen order. check raises its own error for a bad item and may return a normalized +-- replacement; returning nothing keeps the item. +local function unique_query_values(values, check) + local unique, seen = {}, {} + for index, item in ipairs(values) do + local value = check and check(item, index) or item + if not seen[value] then + seen[value] = true + unique[#unique + 1] = value + end + end + return unique +end diff --git a/happyview-modules/lua/shared/workscopeTagList.lua b/happyview-modules/lua/shared/workscopeTagList.lua index e29d5103..a8af69de 100644 --- a/happyview-modules/lua/shared/workscopeTagList.lua +++ b/happyview-modules/lua/shared/workscopeTagList.lua @@ -1,44 +1,16 @@ -local function workscope_tag_array(key) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, did in ipairs(supplied) do +local function workscope_tag_filter_values(key) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(did) if not valid_did(did) then invalid("each " .. key .. " value must be a valid DID; resolve handles to DIDs first") end - if not seen[did] then - seen[did] = true - unique[#unique + 1] = did - end - end - return unique + end) end local function workscope_tag_list() keys_only(params, { authors = true, sortDirection = true, limit = true, cursor = true }) - local authors = workscope_tag_array("authors") + local authors = workscope_tag_filter_values("authors") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, WORKSCOPE_TAG) diff --git a/happyview-modules/lua/src/getReactionCounts.lua b/happyview-modules/lua/src/getReactionCounts.lua index 025f20ea..f5f96274 100644 --- a/happyview-modules/lua/src/getReactionCounts.lua +++ b/happyview-modules/lua/src/getReactionCounts.lua @@ -1,3 +1,5 @@ +-- Not query_string_values: subjects is required, keeps duplicates in request order, stops +-- counting at 101 entries, and reports the range as "subjects must contain 1 through 100 AT-URIs". local function reaction_count_subjects() local value = params.subjects if value == nil then invalid("subjects is required") end diff --git a/happyview-modules/lua/src/listBadgeAwards.lua b/happyview-modules/lua/src/listBadgeAwards.lua index 8915e043..9e8bd1ff 100644 --- a/happyview-modules/lua/src/listBadgeAwards.lua +++ b/happyview-modules/lua/src/listBadgeAwards.lua @@ -8,11 +8,6 @@ local function valid_badge_award_uri(value) return valid and collection == AWARD end -local function valid_badge_definition_uri(value) - local valid, collection = valid_record_uri(value) - return valid and collection == DEFINITION -end - local function query(sql, values) if db.backend() ~= "postgres" then error("BadgeAwardQueryFailed: badge award API requires PostgreSQL", 0) @@ -22,27 +17,15 @@ local function query(sql, values) return result end -local function array_values(key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for i = 1, #value do - if type(value[i]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[i] - end - else invalid(key .. " must be a string or repeated string parameter") end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function badge_award_filter_values(key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique + end) end local function subject_values() @@ -118,22 +101,6 @@ local function add_subject_filter(where, values, subjects) else where[#where + 1] = "(" .. table.concat(clauses, " OR ") .. ")" end end -local function decode_badge_award_cursor(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_badge_award_uri(value.u) then invalid("cursor is malformed") end - return value -end - local function recipient_did_expression() local subject = "award.record::jsonb->'subject'" return "CASE WHEN jsonb_typeof(" .. subject .. ") = 'string' THEN award.record::jsonb->>'subject' " .. @@ -294,15 +261,15 @@ local function handle_list_badge_awards() authors = true, badgeUris = true, badgeTypes = true, subjects = true, responses = true, sortDirection = true, limit = true, cursor = true, includeTotal = true, }) - local authors = array_values("authors", valid_did, "valid DIDs") - local badge_uris = array_values("badgeUris", valid_badge_definition_uri, "badge-definition AT-URIs") - local badge_types = array_values("badgeTypes", nil, nil, 100) + local authors = badge_award_filter_values("authors", valid_did, "valid DIDs") + local badge_uris = badge_award_filter_values("badgeUris", valid_badge_definition_uri, "badge-definition AT-URIs") + local badge_types = badge_award_filter_values("badgeTypes", nil, nil, 100) local subjects = subject_values() - local responses = array_values("responses", function(value) return RESPONSE_STATUSES[value] == true end, + local responses = badge_award_filter_values("responses", function(value) return RESPONSE_STATUSES[value] == true end, "accepted, rejected, or unanswered statuses") local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_badge_award_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_badge_award_uri) local include_total = parse_include_total(params) local views, next_cursor, total_count = list_badge_awards(authors, badge_uris, badge_types, subjects, responses, limit, cursor, direction, include_total) diff --git a/happyview-modules/lua/src/listBadgeDefinitions.lua b/happyview-modules/lua/src/listBadgeDefinitions.lua index 04adc448..60c44651 100644 --- a/happyview-modules/lua/src/listBadgeDefinitions.lua +++ b/happyview-modules/lua/src/listBadgeDefinitions.lua @@ -6,27 +6,15 @@ local function query(sql, values) return result end -local function badge_definition_array(params, key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for i = 1, #value do - if type(value[i]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[i] - end - else invalid(key .. " must be a string or repeated string parameter") end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function badge_definition_filter_values(params, key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique + end) end local function add_badge_definition_filter(where, values, column, items) @@ -40,24 +28,6 @@ local function add_badge_definition_filter(where, values, column, items) where[#where + 1] = column .. " IN (" .. table.concat(placeholders, ",") .. ")" end -local function decode_badge_definition_cursor(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_badge_definition_uri(value.u) then - invalid("cursor is malformed") - end - return value -end - local function list_badge_definitions(authors, badge_types, limit, cursor, direction) if db.backend() ~= "postgres" then error("BadgeDefinitionQueryFailed: badge definition API requires PostgreSQL", 0) @@ -102,11 +72,11 @@ end local function handle_list_badge_definitions() keys_only(params, { authors = true, badgeTypes = true, limit = true, cursor = true, sortDirection = true }) - local authors = badge_definition_array(params, "authors", valid_did, "valid DIDs") - local badge_types = badge_definition_array(params, "badgeTypes", nil, nil, 100) + local authors = badge_definition_filter_values(params, "authors", valid_did, "valid DIDs") + local badge_types = badge_definition_filter_values(params, "badgeTypes", nil, nil, 100) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_badge_definition_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_badge_definition_uri) local views, next_cursor = list_badge_definitions(authors, badge_types, limit, cursor, direction) local response = { badgeDefinitions = toarray(views) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/src/listBadgeResponses.lua b/happyview-modules/lua/src/listBadgeResponses.lua index cb0c4a61..f5303ed9 100644 --- a/happyview-modules/lua/src/listBadgeResponses.lua +++ b/happyview-modules/lua/src/listBadgeResponses.lua @@ -20,22 +20,6 @@ local function query(sql, values) return result end -local function decode_badge_response_cursor(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_badge_response_uri(value.u) then invalid("cursor is malformed") end - return value -end - local function list_badge_responses(badge_award, limit, cursor, direction) local where, values = { "response.collection = $1" }, { RESPONSE } if badge_award then @@ -95,7 +79,7 @@ local function handle_list_badge_responses() end local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_badge_response_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_badge_response_uri) local views, next_cursor = list_badge_responses(badge_award, limit, cursor, direction) local result = { badgeResponses = toarray(views) } if next_cursor then result.cursor = next_cursor end diff --git a/happyview-modules/lua/src/listContributions.lua b/happyview-modules/lua/src/listContributions.lua index 7aa5bb10..06e1a328 100644 --- a/happyview-modules/lua/src/listContributions.lua +++ b/happyview-modules/lua/src/listContributions.lua @@ -1,37 +1,9 @@ local function contribution_authors() - local value = params.authors - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid("authors must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid("authors must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid("authors entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid("authors must be a string or repeated string parameter") - end - if #supplied > 100 then invalid("authors accepts at most 100 values") end - - local authors, seen = {}, {} - for _, did in ipairs(supplied) do + local supplied = query_string_values(params, "authors") + if not supplied then return nil end + return unique_query_values(supplied, function(did) if not valid_did(did) then invalid("each authors value must be a valid DID; resolve handles to DIDs first") end - if not seen[did] then - seen[did] = true - authors[#authors + 1] = did - end - end - return authors + end) end local function contribution_sort_key() diff --git a/happyview-modules/lua/src/listContributorInformation.lua b/happyview-modules/lua/src/listContributorInformation.lua index d0d15947..74e1f1e1 100644 --- a/happyview-modules/lua/src/listContributorInformation.lua +++ b/happyview-modules/lua/src/listContributorInformation.lua @@ -10,42 +10,14 @@ local function contributor_information_query(sql, values) return result end -local function contributor_information_array(params, key, validate, description) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function contributor_information_filter_values(params, key, validate, description) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description .. "; resolve handles to DIDs first") end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function preserve_contributor_author_timestamps(author) @@ -111,7 +83,7 @@ function handle() limit = true, cursor = true, }) - local authors = contributor_information_array(params, "authors", valid_did, "valid DIDs") + local authors = contributor_information_filter_values(params, "authors", valid_did, "valid DIDs") local limit = parse_list_limit(params) local direction = parse_sort_direction(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, contributor_information_uri) diff --git a/happyview-modules/lua/src/listEvmLinks.lua b/happyview-modules/lua/src/listEvmLinks.lua index 745d72f3..c3d7abf3 100644 --- a/happyview-modules/lua/src/listEvmLinks.lua +++ b/happyview-modules/lua/src/listEvmLinks.lua @@ -13,34 +13,15 @@ local function valid_evm_address(value) return #value == 42 and value:match("^0x%x+$") ~= nil end -local function array_values(key, validate, description, normalize) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then - values[1] = value - elseif type(value) == "table" then - for index = 1, #value do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for index, item in ipairs(values) do +local function evm_link_filter_values(key, validate, description, normalize) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item, index) if not validate(item) then invalid(key .. "[" .. index .. "] must be " .. description) end - local normalized = normalize and normalize(item) or item - if not seen[normalized] then - seen[normalized] = true - unique[#unique + 1] = normalized - end - end - return unique + return normalize and normalize(item) or item + end) end local function add_filter(where, values, expression, items) @@ -57,26 +38,6 @@ local function add_filter(where, values, expression, items) where[#where + 1] = expression .. " IN (" .. table.concat(placeholders, ",") .. ")" end -local function decode_evm_link_cursor(token, direction) - if not token then return nil end - if #token == 0 or #token % 2 ~= 0 or token:find("[^0-9a-f]") then - invalid("cursor is malformed") - end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_evm_link_uri(value.u) then - invalid("cursor is malformed") - end - return value -end - local function list_evm_links(actors, addresses, limit, cursor, direction) local where, values = { "link.collection = $1" }, { EVMLINK } add_filter(where, values, "link.did", actors) @@ -130,11 +91,11 @@ function handle() limit = true, cursor = true, }) - local actors = array_values("actors", valid_did, "valid DIDs") - local addresses = array_values("addresses", valid_evm_address, "a 0x-prefixed 40-digit hexadecimal EVM address", string.lower) + local actors = evm_link_filter_values("actors", valid_did, "valid DIDs") + local addresses = evm_link_filter_values("addresses", valid_evm_address, "a 0x-prefixed 40-digit hexadecimal EVM address", string.lower) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_evm_link_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_evm_link_uri) local views, next_cursor = list_evm_links(actors, addresses, limit, cursor, direction) local response = { evmLinks = toarray(views) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/src/listFeatures.lua b/happyview-modules/lua/src/listFeatures.lua index 9de46453..1518d231 100644 --- a/happyview-modules/lua/src/listFeatures.lua +++ b/happyview-modules/lua/src/listFeatures.lua @@ -1,41 +1,14 @@ local FEATURE_VIEW_TYPE = "org.hypercerts.entity.defs#featureView" -local function feature_array(params, key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then - values[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated string query parameters") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated string query parameters") end - for index = 1, #value do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function feature_filter_values(params, key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique + end) end local function feature_add_types(where, values, binds) @@ -63,26 +36,6 @@ local function feature_parse_organization_filter(params) invalid("hasOrganizationRecord must be true or false") end -local function feature_cursor_decode(token, direction) - if token == nil then return nil end - if type(token) ~= "string" or #token > 32768 or #token % 2 ~= 0 or token:find("[^0-9a-f]") then - invalid("cursor is malformed") - end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not feature_valid_uri(value.u) or not valid_datetime(value.t) then - invalid("cursor is malformed") - end - return value -end - local function feature_query_rows(sql, binds) if db.backend() ~= "postgres" then error("FeatureQueryFailed: feature API requires PostgreSQL", 0) end local ok, rows = pcall(db.raw, sql, binds) @@ -146,14 +99,14 @@ local function list_features() limit = true, cursor = true, }) - local authors = feature_array(params, "authors", valid_did, "valid DIDs") - local types = feature_array(params, "types", nil, nil, 64) + local authors = feature_filter_values(params, "authors", valid_did, "valid DIDs") + local types = feature_filter_values(params, "types", nil, nil, 64) local has_organization_record = feature_parse_organization_filter(params) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) local cursor_value = params.cursor if cursor_value ~= nil and type(cursor_value) ~= "string" then invalid("cursor must occur once as a string") end - local cursor = feature_cursor_decode(cursor_value, direction) + local cursor = decode_record_cursor(cursor_value, direction, feature_valid_uri) local rows = feature_list_rows({ authors = authors, hasOrganizationRecord = has_organization_record, diff --git a/happyview-modules/lua/src/listLocations.lua b/happyview-modules/lua/src/listLocations.lua index 4cb48ff8..c5e16d0a 100644 --- a/happyview-modules/lua/src/listLocations.lua +++ b/happyview-modules/lua/src/listLocations.lua @@ -1,25 +1,13 @@ -local function array(params, key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for i = 1, #value do - if type(value[i]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[i] - end - else invalid(key .. " must be a string or repeated string parameter") end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function location_filter_values(params, key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique + end) end -local function add_in(where, params, column, values) +local function add_optional_in(where, params, column, values) if not values then return end if #values == 0 then where[#where + 1] = "FALSE"; return end local placeholders = {} @@ -30,28 +18,12 @@ local function add_in(where, params, column, values) where[#where + 1] = column .. " IN (" .. table.concat(placeholders, ",") .. ")" end -local function cursor_decode(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_location_uri(value.u) or not valid_datetime(value.t) then invalid("cursor is malformed") end - return value -end - local function query_locations(filters, limit, cursor, direction) if db.backend() ~= "postgres" then error("LocationQueryFailed: location API requires PostgreSQL", 0) end local where, binds = { "collection = $1" }, { COLLECTION } - add_in(where, binds, "did", filters.authors) - add_in(where, binds, "uri", filters.uris) - add_in(where, binds, "(record::jsonb)->>'locationType'", filters.locationTypes) + add_optional_in(where, binds, "did", filters.authors) + add_optional_in(where, binds, "uri", filters.uris) + add_optional_in(where, binds, "(record::jsonb)->>'locationType'", filters.locationTypes) if cursor then binds[#binds + 1] = cursor.t local time = "$" .. #binds @@ -79,12 +51,12 @@ end local function list_locations() keys_only(params, { authors = true, uris = true, locationTypes = true, limit = true, cursor = true, sortDirection = true }) - local authors = array(params, "authors", valid_did, "valid DIDs") - local uris = array(params, "uris", valid_location_uri, "full app.certified.location AT-URIs with DID authorities") - local types = array(params, "locationTypes", nil, nil, 20) + local authors = location_filter_values(params, "authors", valid_did, "valid DIDs") + local uris = location_filter_values(params, "uris", valid_location_uri, "full app.certified.location AT-URIs with DID authorities") + local types = location_filter_values(params, "locationTypes", nil, nil, 20) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = cursor_decode(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_location_uri) local views, next_cursor = query_locations({ authors = authors, uris = uris, locationTypes = types }, limit, cursor, direction) local response = { locations = toarray(views) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/lua/src/listMeasurements.lua b/happyview-modules/lua/src/listMeasurements.lua index 29d79eab..087299c8 100644 --- a/happyview-modules/lua/src/listMeasurements.lua +++ b/happyview-modules/lua/src/listMeasurements.lua @@ -1,30 +1,7 @@ -local function measurement_array(key, format) - local value = params[key] - if value == nil then return nil end - - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid(key .. " must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid(key .. " must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid(key .. " entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid(key .. " must be a string or repeated string parameter") - end - if #supplied > 100 then invalid(key .. " accepts at most 100 values") end - - local unique, seen = {}, {} - for _, item in ipairs(supplied) do +local function measurement_filter_values(key, format) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if format == "did" and not valid_did(item) then invalid("each " .. key .. " value must be a valid DID") elseif format == "at-uri" then @@ -33,21 +10,7 @@ local function measurement_array(key, format) invalid("each " .. key .. " value must be a full AT-URI with a DID authority and valid collection NSID") end end - if not seen[item] then - seen[item] = true - unique[#unique + 1] = item - end - end - return unique -end - -local function bind_values(values, items) - local placeholders = {} - for _, item in ipairs(items) do - values[#values + 1] = item - placeholders[#placeholders + 1] = "$" .. #values - end - return placeholders + end) end local function measurement_list_query(authors, subjects, limit, cursor, direction) @@ -110,8 +73,8 @@ function handle() cursor = true, }) - local authors = measurement_array("authors", "did") - local subjects = measurement_array("subjects", "at-uri") + local authors = measurement_filter_values("authors", "did") + local subjects = measurement_filter_values("subjects", "at-uri") local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, MEASUREMENT) diff --git a/happyview-modules/lua/src/listRights.lua b/happyview-modules/lua/src/listRights.lua index 82f960ec..fc4eecef 100644 --- a/happyview-modules/lua/src/listRights.lua +++ b/happyview-modules/lua/src/listRights.lua @@ -7,40 +7,6 @@ local function rights_list_run_query(sql, values) return result end -local function rights_list_array(value) - if value == nil then return nil end - local supplied = {} - if type(value) == "string" then - supplied[1] = value - elseif type(value) == "table" then - local count = 0 - for index in pairs(value) do - if type(index) ~= "number" or index < 1 or index % 1 ~= 0 then - invalid("authors must use repeated query values") - end - count = count + 1 - end - if count ~= #value then invalid("authors must use repeated query values") end - for index = 1, count do - if type(value[index]) ~= "string" then invalid("authors entries must be strings") end - supplied[#supplied + 1] = value[index] - end - else - invalid("authors must be a string or repeated string parameter") - end - if #supplied > 100 then invalid("authors accepts at most 100 values") end - - local unique, seen = {}, {} - for _, did in ipairs(supplied) do - if not valid_did(did) then invalid("each authors value must be a valid DID") end - if not seen[did] then - seen[did] = true - unique[#unique + 1] = did - end - end - return unique -end - local function rights_list_query(authors, limit, cursor, direction) local where, values = { "rights.collection = $1" }, { RIGHTS } @@ -87,7 +53,10 @@ end local function rights_list_response() keys_only(params, { authors = true, sortDirection = true, limit = true, cursor = true }) - local authors = rights_list_array(params.authors) + local authors = query_string_values(params, "authors") + authors = authors and unique_query_values(authors, function(did) + if not valid_did(did) then invalid("each authors value must be a valid DID") end + end) local direction = parse_sort_direction(params) local limit = parse_list_limit(params) local cursor = decode_record_cursor(scalar(params, "cursor"), direction, RIGHTS) diff --git a/happyview-modules/lua/src/listVocabTags.lua b/happyview-modules/lua/src/listVocabTags.lua index 8fb751a9..8eda1043 100644 --- a/happyview-modules/lua/src/listVocabTags.lua +++ b/happyview-modules/lua/src/listVocabTags.lua @@ -6,6 +6,9 @@ local function query(sql, values) return result end +-- Not query_string_values: its shape error is "authors must be repeated string values" +-- (the shared parser says "must use repeated query values"), and the result is sorted +-- because the author list is part of the cursor signature. local function parse_authors(value) if value == nil then return nil end local supplied = {} diff --git a/happyview-modules/lua/src/searchBadgeDefinitions.lua b/happyview-modules/lua/src/searchBadgeDefinitions.lua index 76d71297..37e4ac3f 100644 --- a/happyview-modules/lua/src/searchBadgeDefinitions.lua +++ b/happyview-modules/lua/src/searchBadgeDefinitions.lua @@ -9,27 +9,15 @@ local function query(sql, values) return result end -local function badge_definition_array(key, validate, description, max_bytes) - local value = params[key] - if value == nil then return nil end - local values = {} - if type(value) == "string" then values[1] = value - elseif type(value) == "table" then - for i = 1, #value do - if type(value[i]) ~= "string" then invalid(key .. " entries must be strings") end - values[#values + 1] = value[i] - end - else invalid(key .. " must be a string or repeated string parameter") end - if #values > 100 then invalid(key .. " accepts at most 100 values") end - local unique, seen = {}, {} - for _, item in ipairs(values) do +local function badge_definition_filter_values(key, validate, description, max_bytes) + local supplied = query_string_values(params, key) + if not supplied then return nil end + return unique_query_values(supplied, function(item) if max_bytes and #item > max_bytes then invalid(key .. " entries must be at most " .. max_bytes .. " UTF-8 bytes") end if validate and not validate(item) then invalid("each " .. key .. " value must be " .. description) end - if not seen[item] then seen[item] = true; unique[#unique + 1] = item end - end - return unique + end) end local function add_badge_definition_filter(where, values, column, items) @@ -43,24 +31,6 @@ local function add_badge_definition_filter(where, values, column, items) where[#where + 1] = column .. " IN (" .. table.concat(placeholders, ",") .. ")" end -local function decode_badge_definition_cursor(token, direction) - if not token then return nil end - if #token % 2 ~= 0 or token:find("[^0-9a-f]") then invalid("cursor is malformed") end - local decoded = token:gsub("..", function(pair) return string.char(tonumber(pair, 16)) end) - local ok, value = pcall(json.decode, decoded) - if not ok or type(value) ~= "table" or value.v ~= 1 or value.d ~= direction - or type(value.t) ~= "string" or type(value.u) ~= "string" then - invalid("cursor is malformed or belongs to another sortDirection") - end - for key in pairs(value) do - if key ~= "v" and key ~= "d" and key ~= "t" and key ~= "u" then invalid("cursor is malformed") end - end - if not valid_datetime(value.t) or not valid_badge_definition_uri(value.u) then - invalid("cursor is malformed") - end - return value -end - local function query_badge_definitions(authors, badge_types, search, limit, cursor, direction) local where, values = { "collection = $1" }, { COLLECTION } add_badge_definition_filter(where, values, "did", authors) @@ -123,11 +93,11 @@ local function handle_search_badge_definitions() if search == nil then invalid("search is required") end search = search:match("^%s*(.-)%s*$") if search == "" then search = nil end - local authors = badge_definition_array("authors", valid_did, "valid DIDs") - local badge_types = badge_definition_array("badgeTypes", nil, nil, 100) + local authors = badge_definition_filter_values("authors", valid_did, "valid DIDs") + local badge_types = badge_definition_filter_values("badgeTypes", nil, nil, 100) local limit = parse_list_limit(params) local direction = parse_sort_direction(params) - local cursor = decode_badge_definition_cursor(scalar(params, "cursor"), direction) + local cursor = decode_record_cursor(scalar(params, "cursor"), direction, valid_badge_definition_uri) local views, next_cursor = query_badge_definitions(authors, badge_types, search, limit, cursor, direction) local response = { badgeDefinitions = toarray(views) } if next_cursor then response.cursor = next_cursor end diff --git a/happyview-modules/modules/acknowledgements/manifest.json b/happyview-modules/modules/acknowledgements/manifest.json index 935e1f16..034b984e 100644 --- a/happyview-modules/modules/acknowledgements/manifest.json +++ b/happyview-modules/modules/acknowledgements/manifest.json @@ -64,6 +64,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/activity/manifest.json b/happyview-modules/modules/activity/manifest.json index eab0df97..f5cab522 100644 --- a/happyview-modules/modules/activity/manifest.json +++ b/happyview-modules/modules/activity/manifest.json @@ -48,6 +48,7 @@ "../../lua/shared/recordIdentifier.lua", "../../lua/shared/activityProjection.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/activity.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", @@ -74,6 +75,7 @@ "../../lua/shared/recordIdentifier.lua", "../../lua/shared/activityProjection.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/activity.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/badge-definitions/manifest.json b/happyview-modules/modules/badge-definitions/manifest.json index dd30d201..790c73ee 100644 --- a/happyview-modules/modules/badge-definitions/manifest.json +++ b/happyview-modules/modules/badge-definitions/manifest.json @@ -52,6 +52,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/badgeDefinitionValidation.lua", "../../lua/shared/datetimeValidation.lua", diff --git a/happyview-modules/modules/badge-queries/manifest.json b/happyview-modules/modules/badge-queries/manifest.json index 4bb02420..2ad0c8bc 100644 --- a/happyview-modules/modules/badge-queries/manifest.json +++ b/happyview-modules/modules/badge-queries/manifest.json @@ -62,6 +62,7 @@ "sourcePath": "../../lua/src/searchBadgeDefinitions.lua", "sharedSourcePaths": [ "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/didValidation.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/badgeDefinitionValidation.lua", @@ -104,9 +105,11 @@ "sourcePath": "../../lua/src/listBadgeAwards.lua", "sharedSourcePaths": [ "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/includeTotal.lua", "../../lua/shared/didValidation.lua", "../../lua/shared/recordIdentifier.lua", + "../../lua/shared/badgeDefinitionValidation.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listCursor.lua", diff --git a/happyview-modules/modules/collection/manifest.json b/happyview-modules/modules/collection/manifest.json index e3c2c243..4823e82a 100644 --- a/happyview-modules/modules/collection/manifest.json +++ b/happyview-modules/modules/collection/manifest.json @@ -43,6 +43,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/createdAtSort.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listCursor.lua", "../../lua/shared/listQuery.lua", @@ -80,6 +81,7 @@ "../../lua/shared/datetimeValidation.lua", "../../lua/shared/createdAtSort.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/listValidation.lua", "../../lua/shared/listCursor.lua", "../../lua/shared/listQuery.lua", diff --git a/happyview-modules/modules/context-attachments/manifest.json b/happyview-modules/modules/context-attachments/manifest.json index 74360220..da50b107 100644 --- a/happyview-modules/modules/context-attachments/manifest.json +++ b/happyview-modules/modules/context-attachments/manifest.json @@ -47,6 +47,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/context-evaluation/manifest.json b/happyview-modules/modules/context-evaluation/manifest.json index e417f4aa..1acfb557 100644 --- a/happyview-modules/modules/context-evaluation/manifest.json +++ b/happyview-modules/modules/context-evaluation/manifest.json @@ -47,6 +47,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/context-measurements/manifest.json b/happyview-modules/modules/context-measurements/manifest.json index b3cbfa3c..4b549279 100644 --- a/happyview-modules/modules/context-measurements/manifest.json +++ b/happyview-modules/modules/context-measurements/manifest.json @@ -46,6 +46,7 @@ "sourcePath": "../../lua/src/listMeasurements.lua", "sharedSourcePaths": [ "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/didValidation.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", diff --git a/happyview-modules/modules/contribution/manifest.json b/happyview-modules/modules/contribution/manifest.json index 8c8b8e00..ea1d9e50 100644 --- a/happyview-modules/modules/contribution/manifest.json +++ b/happyview-modules/modules/contribution/manifest.json @@ -38,6 +38,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/contributor-information/manifest.json b/happyview-modules/modules/contributor-information/manifest.json index bb1b33db..21704881 100644 --- a/happyview-modules/modules/contributor-information/manifest.json +++ b/happyview-modules/modules/contributor-information/manifest.json @@ -50,6 +50,7 @@ "sourcePath": "../../lua/src/listContributorInformation.lua", "sharedSourcePaths": [ "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/didValidation.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/contributorInformationValidation.lua", diff --git a/happyview-modules/modules/evm-links/manifest.json b/happyview-modules/modules/evm-links/manifest.json index c4e7944f..da597a7e 100644 --- a/happyview-modules/modules/evm-links/manifest.json +++ b/happyview-modules/modules/evm-links/manifest.json @@ -48,6 +48,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/features/manifest.json b/happyview-modules/modules/features/manifest.json index b524da52..79cc9619 100644 --- a/happyview-modules/modules/features/manifest.json +++ b/happyview-modules/modules/features/manifest.json @@ -45,6 +45,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/funding/manifest.json b/happyview-modules/modules/funding/manifest.json index 35c2826c..f58f8f71 100644 --- a/happyview-modules/modules/funding/manifest.json +++ b/happyview-modules/modules/funding/manifest.json @@ -47,6 +47,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/location/manifest.json b/happyview-modules/modules/location/manifest.json index f9253566..ebcbe2df 100644 --- a/happyview-modules/modules/location/manifest.json +++ b/happyview-modules/modules/location/manifest.json @@ -47,6 +47,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/organization/manifest.json b/happyview-modules/modules/organization/manifest.json index beebbbdf..67e6d0aa 100644 --- a/happyview-modules/modules/organization/manifest.json +++ b/happyview-modules/modules/organization/manifest.json @@ -91,6 +91,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", @@ -119,6 +120,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/profile/manifest.json b/happyview-modules/modules/profile/manifest.json index d6f9b966..8926b8db 100644 --- a/happyview-modules/modules/profile/manifest.json +++ b/happyview-modules/modules/profile/manifest.json @@ -84,6 +84,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", @@ -109,6 +110,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/modules/rights/manifest.json b/happyview-modules/modules/rights/manifest.json index e66b5b97..6feb760a 100644 --- a/happyview-modules/modules/rights/manifest.json +++ b/happyview-modules/modules/rights/manifest.json @@ -37,6 +37,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/recordView.lua", "../../lua/shared/actorView.lua", diff --git a/happyview-modules/modules/workscope-tags/manifest.json b/happyview-modules/modules/workscope-tags/manifest.json index 7098015a..bce69656 100644 --- a/happyview-modules/modules/workscope-tags/manifest.json +++ b/happyview-modules/modules/workscope-tags/manifest.json @@ -47,6 +47,7 @@ "sharedSourcePaths": [ "../../lua/shared/didValidation.lua", "../../lua/shared/query.lua", + "../../lua/shared/queryArray.lua", "../../lua/shared/recordIdentifier.lua", "../../lua/shared/datetimeValidation.lua", "../../lua/shared/listValidation.lua", diff --git a/happyview-modules/tests/http/query-array-shapes.http.test.js b/happyview-modules/tests/http/query-array-shapes.http.test.js new file mode 100644 index 00000000..0414fffb --- /dev/null +++ b/happyview-modules/tests/http/query-array-shapes.http.test.js @@ -0,0 +1,43 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { requireContractTarget } from "./helpers.js"; + +// A repeated array parameter reaches Lua as a list (`?k=a&k=b`). HappyView does not +// build keyed or sparse tables from `k[x]`, `k[2]`, `k.x`: it hands those over as +// differently named parameters, which the handlers' unknown-parameter check rejects +// before any array parser runs. The array parsers can therefore treat a non-list +// table as impossible input. +const KEYED_FORMS = (key) => [`${key}[x]`, `${key}[2]`, `${key}[0]`, `${key}[]`, `${key}.x`]; + +const ENDPOINTS = [ + ["app.certified.actor.searchProfiles", "search=a", ["actors"]], + [ + "app.certified.badge.listBadgeAwards", + "", + ["authors", "badgeUris", "badgeTypes", "subjects", "responses"], + ], + ["app.certified.badge.listBadgeDefinitions", "", ["authors", "badgeTypes"]], + ["app.certified.badge.searchBadgeDefinitions", "search=a", ["authors", "badgeTypes"]], + ["app.certified.link.listEvmLinks", "", ["actors", "addresses"]], + ["app.certified.location.listLocations", "", ["authors", "uris", "locationTypes"]], + ["org.hypercerts.entity.listFeatures", "", ["authors", "types"]], +]; + +test("keyed and sparse array-parameter spellings never reach the array parsers", async () => { + const base = requireContractTarget(); + for (const [nsid, fixed, keys] of ENDPOINTS) { + for (const key of keys) { + for (const spelling of KEYED_FORMS(key)) { + const url = `${base.origin}/xrpc/${nsid}?${fixed ? `${fixed}&` : ""}${encodeURIComponent(spelling)}=x`; + const response = await fetch(url, { signal: AbortSignal.timeout(10_000) }); + const body = await response.json(); + assert.notEqual(response.status, 200, `${nsid} accepted ${spelling}`); + assert.match( + body.message, + /InvalidRequest: unknown query parameter/, + `${nsid} ${spelling}`, + ); + } + } + } +}); diff --git a/happyview-modules/tests/unit/endpoints/rights-edge-lua.test.js b/happyview-modules/tests/unit/endpoints/rights-edge-lua.test.js index 5b606cfe..78beb9de 100644 --- a/happyview-modules/tests/unit/endpoints/rights-edge-lua.test.js +++ b/happyview-modules/tests/unit/endpoints/rights-edge-lua.test.js @@ -11,6 +11,7 @@ async function endpointSources(name) { const shared = [ "lua/shared/didValidation.lua", "lua/shared/query.lua", + "lua/shared/queryArray.lua", "lua/shared/recordIdentifier.lua", "lua/shared/recordView.lua", "lua/shared/actorView.lua", diff --git a/happyview-modules/tests/unit/endpoints/rights-lua.test.js b/happyview-modules/tests/unit/endpoints/rights-lua.test.js index 1628aa99..e2605247 100644 --- a/happyview-modules/tests/unit/endpoints/rights-lua.test.js +++ b/happyview-modules/tests/unit/endpoints/rights-lua.test.js @@ -86,6 +86,7 @@ async function listRightsSources() { return Promise.all([ read("lua/shared/didValidation.lua"), read("lua/shared/query.lua"), + read("lua/shared/queryArray.lua"), read("lua/shared/recordIdentifier.lua"), read("lua/shared/recordView.lua"), read("lua/shared/actorView.lua"), diff --git a/happyview-modules/tests/unit/feature.test.js b/happyview-modules/tests/unit/feature.test.js index 12c546b6..17acd4cb 100644 --- a/happyview-modules/tests/unit/feature.test.js +++ b/happyview-modules/tests/unit/feature.test.js @@ -135,6 +135,7 @@ async function runListFeatures( [ "lua/shared/didValidation.lua", "lua/shared/query.lua", + "lua/shared/queryArray.lua", "lua/shared/recordIdentifier.lua", "lua/shared/datetimeValidation.lua", "lua/shared/listValidation.lua", diff --git a/happyview-modules/tests/unit/list-golden/cursor-size.test.js b/happyview-modules/tests/unit/list-golden/cursor-size.test.js new file mode 100644 index 00000000..3332318b --- /dev/null +++ b/happyview-modules/tests/unit/list-golden/cursor-size.test.js @@ -0,0 +1,46 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { maximalCursorCase } from "./fixtures.js"; +import { listCursorEndpoints, runCases } from "./harness.js"; + +// Every list endpoint shares one 8192-character cursor cap on decode. This proves +// the cap cannot reject a cursor the API itself issued: it builds the largest page +// cursor each endpoint can emit (longest DID and record key the handlers accept), +// checks it against the cap with the longest possible collection NSID instead of the +// endpoint's real one, and replays it as the next request. +const CURSOR_CAP = 8192; +const MAX_NSID_LENGTH = 317; + +test("the largest cursor each list endpoint issues is below the decode cap and is accepted on replay", async () => { + const endpoints = await listCursorEndpoints(); + let checked = 0; + for (const endpoint of endpoints) { + const big = maximalCursorCase(endpoint); + if (!big) continue; + const [issued] = runCases(endpoint.source, [big]); + const cursor = issued.outcome.result?.cursor; + assert.equal( + typeof cursor, + "string", + `${endpoint.id}: no cursor issued (${JSON.stringify(issued.outcome).slice(0, 200)})`, + ); + // The NSID appears once in the URI, so each extra character adds two hex characters. + const worstCase = cursor.length + 2 * (MAX_NSID_LENGTH - big.collection.length); + assert.ok( + worstCase < CURSOR_CAP, + `${endpoint.id}: worst-case cursor is ${worstCase} characters, cap is ${CURSOR_CAP}`, + ); + + const [replay] = runCases(endpoint.source, [ + { name: "replay", params: { ...big.params, cursor } }, + ]); + // A later failure (e.g. a count query the fake db cannot answer) is fine; a cursor rejection is not. + assert.doesNotMatch( + replay.outcome.error ?? "", + /^InvalidRequest/, + `${endpoint.id}: own cursor rejected on replay: ${replay.outcome.error}`, + ); + checked += 1; + } + assert.ok(checked >= 30, `only ${checked} endpoints checked`); +}); diff --git a/happyview-modules/tests/unit/list-golden/fixtures.js b/happyview-modules/tests/unit/list-golden/fixtures.js index be5b1a9b..f8dde03a 100644 --- a/happyview-modules/tests/unit/list-golden/fixtures.js +++ b/happyview-modules/tests/unit/list-golden/fixtures.js @@ -700,6 +700,46 @@ function defaultRowsByCall(endpoint) { export const CURSOR_FIXTURE_IDS = Object.keys(CURSORS); +/** + * Endpoints whose cursor size is not bounded by an AT-URI: listRecentFollows echoes + * the caller's unbounded `before` datetime and listVocabTags echoes its author + * filter, so they keep their own decoders and no length cap. + */ +const UNBOUNDED_CURSOR_IDS = new Set([ + "app.certified.graph.listRecentFollows", + "org.hypercerts.vocab.listVocabTags", +]); + +/** + * A page whose rows carry the longest record URI the handlers accept (2048-character + * DID, 512-character record key), so the cursor it issues is the largest possible one + * for that endpoint's collection. Null for endpoints without a size bound. + */ +export function maximalCursorCase(endpoint) { + const spec = CURSORS[endpoint.id]; + if (!spec?.collection || UNBOUNDED_CURSOR_IDS.has(endpoint.id)) return null; + const did = `did:plc:${"a".repeat(2040)}`; + const rows = Array.from({ length: PAGE_ROWS }, (_, n) => ({ + ...pageRow(endpoint, n), + uri: `at://${did}/${spec.collection}/${spec.rkey ?? "k".repeat(512)}`, + did, + actor_did: did, + subject_did: did, + })); + const direction = endpoint.properties.sortDirection ? "desc" : undefined; + return { + collection: spec.collection, + direction, + name: "maximal-cursor", + params: { + ...baseParams(endpoint), + ...(direction ? { sortDirection: direction } : {}), + limit: PAGE_ROWS - 1, + }, + rowsByCall: [direction === "asc" ? rows : rows.toReversed()], + }; +} + /** Fixed input cases for one endpoint. Names starting `year0000:` are quarantined. */ export function casesFor(endpoint) { const base = baseParams(endpoint); diff --git a/happyview-modules/tests/unit/list-golden/list-endpoints.golden.jsonl b/happyview-modules/tests/unit/list-golden/list-endpoints.golden.jsonl index 6856a03c..9ed35042 100644 --- a/happyview-modules/tests/unit/list-golden/list-endpoints.golden.jsonl +++ b/happyview-modules/tests/unit/list-golden/list-endpoints.golden.jsonl @@ -368,13 +368,13 @@ {"endpoint":"app.certified.actor.listOrganizations","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.actor.listOrganizations","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.actor.listOrganizations","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.actor.listOrganizations","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.actor.listOrganizations","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listOrganizations","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.actor.listOrganizations","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.actor.listOrganizations","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listOrganizations","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.actor.organization","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.organization/self",26],"sql":"46a96a9b3e"}],"outcome":{"result":{"actors":[]}}} {"endpoint":"app.certified.actor.listOrganizations","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.actor.organization","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.organization/self",26],"sql":"46a96a9b3e"}],"outcome":{"result":{"actors":[]}}} -{"endpoint":"app.certified.actor.listOrganizations","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.actor.organization","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.organization/self",26],"sql":"46a96a9b3e"}],"outcome":{"result":{"actors":[]}}} +{"endpoint":"app.certified.actor.listOrganizations","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listOrganizations","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listOrganizations","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listOrganizations","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.actor.organization","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.organization/self",26],"sql":"46a96a9b3e"}],"outcome":{"result":{"actors":[]}}} @@ -478,13 +478,13 @@ {"endpoint":"app.certified.actor.listProfiles","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.actor.listProfiles","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.actor.listProfiles","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.actor.listProfiles","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.actor.listProfiles","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listProfiles","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.actor.listProfiles","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.actor.listProfiles","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listProfiles","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.actor.profile","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.profile/self",26],"sql":"9e6090d8e4"}],"outcome":{"result":{"profiles":[]}}} {"endpoint":"app.certified.actor.listProfiles","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.actor.profile","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.profile/self",26],"sql":"9e6090d8e4"}],"outcome":{"result":{"profiles":[]}}} -{"endpoint":"app.certified.actor.listProfiles","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.actor.profile","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.profile/self",26],"sql":"9e6090d8e4"}],"outcome":{"result":{"profiles":[]}}} +{"endpoint":"app.certified.actor.listProfiles","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listProfiles","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listProfiles","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.listProfiles","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.actor.profile","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.profile/self",26],"sql":"9e6090d8e4"}],"outcome":{"result":{"profiles":[]}}} @@ -622,13 +622,13 @@ {"endpoint":"app.certified.actor.searchOrganizations","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.actor.searchOrganizations","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.actor.searchOrganizations","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.actor.organization","test","app.certified.actor.profile","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.organization/self",26],"sql":"ba980873dd"}],"outcome":{"result":{"actors":[]}}} {"endpoint":"app.certified.actor.searchOrganizations","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.actor.organization","test","app.certified.actor.profile","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.organization/self",26],"sql":"ba980873dd"}],"outcome":{"result":{"actors":[]}}} -{"endpoint":"app.certified.actor.searchOrganizations","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.actor.organization","test","app.certified.actor.profile","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.organization/self",26],"sql":"ba980873dd"}],"outcome":{"result":{"actors":[]}}} +{"endpoint":"app.certified.actor.searchOrganizations","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchOrganizations","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.actor.organization","test","app.certified.actor.profile","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.organization/self",26],"sql":"ba980873dd"}],"outcome":{"result":{"actors":[]}}} @@ -731,10 +731,10 @@ {"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: actors entries must be strings"}} {"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each actors value must be a valid DID"}} {"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: actors entries must be strings"}} -{"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:keyed-table","calls":[{"binds":["app.certified.actor.profile","did:plc:abcdefghijklmnopqrstuvwx","test",26],"sql":"a4a6ef4bdf"}],"outcome":{"result":{"profiles":[]}}} -{"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:string-keyed-table","calls":[{"binds":["app.certified.actor.profile","test",26],"sql":"d62f1fff4b"}],"outcome":{"result":{"profiles":[]}}} -{"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:sparse-table","calls":[{"binds":["app.certified.actor.profile","did:plc:abcdefghijklmnopqrstuvwx","test",26],"sql":"a4a6ef4bdf"}],"outcome":{"result":{"profiles":[]}}} -{"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:sparse-table-from-2","calls":[{"binds":["app.certified.actor.profile","test",26],"sql":"d62f1fff4b"}],"outcome":{"result":{"profiles":[]}}} +{"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: actors must use repeated query values"}} +{"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: actors must use repeated query values"}} +{"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: actors must use repeated query values"}} +{"endpoint":"app.certified.actor.searchProfiles","case":"array:actors:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: actors must use repeated query values"}} {"endpoint":"app.certified.actor.searchProfiles","case":"error:sortDirection=bad","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} {"endpoint":"app.certified.actor.searchProfiles","case":"error:sortDirection=ASC","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} {"endpoint":"app.certified.actor.searchProfiles","case":"error:sortDirection=empty","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} @@ -747,13 +747,13 @@ {"endpoint":"app.certified.actor.searchProfiles","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.actor.searchProfiles","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.actor.searchProfiles","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.actor.searchProfiles","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.actor.searchProfiles","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchProfiles","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.actor.searchProfiles","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.actor.searchProfiles","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchProfiles","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.actor.profile","test","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.profile/self",26],"sql":"142fb30cf8"}],"outcome":{"result":{"profiles":[]}}} {"endpoint":"app.certified.actor.searchProfiles","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.actor.profile","test","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.profile/self",26],"sql":"142fb30cf8"}],"outcome":{"result":{"profiles":[]}}} -{"endpoint":"app.certified.actor.searchProfiles","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.actor.profile","test","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.profile/self",26],"sql":"142fb30cf8"}],"outcome":{"result":{"profiles":[]}}} +{"endpoint":"app.certified.actor.searchProfiles","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchProfiles","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchProfiles","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.actor.searchProfiles","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.actor.profile","test","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.actor.profile/self",26],"sql":"142fb30cf8"}],"outcome":{"result":{"profiles":[]}}} @@ -865,10 +865,10 @@ {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each authors value must be valid DIDs"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:keyed-table","calls":[{"binds":["app.certified.badge.award","did:plc:abcdefghijklmnopqrstuvwx",26],"sql":"03c5ffce2b"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:string-keyed-table","calls":[{"binds":["app.certified.badge.award",26],"sql":"b54d166028"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:sparse-table","calls":[{"binds":["app.certified.badge.award","did:plc:abcdefghijklmnopqrstuvwx",26],"sql":"03c5ffce2b"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:sparse-table-from-2","calls":[{"binds":["app.certified.badge.award",26],"sql":"b54d166028"}],"outcome":{"result":{"badgeAwards":[]}}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:authors:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:badgeUris:many","calls":[{"binds":["app.certified.badge.award","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghija","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijb","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijc",26],"sql":"dd9ca50998"}],"outcome":{"result":{"badgeAwards":[]}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:badgeUris:one","calls":[{"binds":["app.certified.badge.award","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghija",26],"sql":"792870ea3b"}],"outcome":{"result":{"badgeAwards":[]}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:badgeUris:one-scalar","calls":[{"binds":["app.certified.badge.award","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghija",26],"sql":"792870ea3b"}],"outcome":{"result":{"badgeAwards":[]}}} @@ -880,10 +880,10 @@ {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: badgeUris entries must be strings"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each badgeUris value must be badge-definition AT-URIs"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: badgeUris entries must be strings"}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:keyed-table","calls":[{"binds":["app.certified.badge.award","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghija",26],"sql":"792870ea3b"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:string-keyed-table","calls":[{"binds":["app.certified.badge.award",26],"sql":"b54d166028"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:sparse-table","calls":[{"binds":["app.certified.badge.award","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghija",26],"sql":"792870ea3b"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:sparse-table-from-2","calls":[{"binds":["app.certified.badge.award",26],"sql":"b54d166028"}],"outcome":{"result":{"badgeAwards":[]}}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: badgeUris must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: badgeUris must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: badgeUris must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeUris:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: badgeUris must use repeated query values"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:badgeTypes:many","calls":[{"binds":["app.certified.badge.award","volunteer","contributor","steward",26],"sql":"de8e448a07"}],"outcome":{"result":{"badgeAwards":[]}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:badgeTypes:one","calls":[{"binds":["app.certified.badge.award","volunteer",26],"sql":"49f2ff18af"}],"outcome":{"result":{"badgeAwards":[]}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:badgeTypes:one-scalar","calls":[{"binds":["app.certified.badge.award","volunteer",26],"sql":"49f2ff18af"}],"outcome":{"result":{"badgeAwards":[]}}} @@ -895,10 +895,10 @@ {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be strings"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be at most 100 UTF-8 bytes"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be strings"}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:keyed-table","calls":[{"binds":["app.certified.badge.award","volunteer",26],"sql":"49f2ff18af"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:string-keyed-table","calls":[{"binds":["app.certified.badge.award",26],"sql":"b54d166028"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:sparse-table","calls":[{"binds":["app.certified.badge.award","volunteer",26],"sql":"49f2ff18af"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:sparse-table-from-2","calls":[{"binds":["app.certified.badge.award",26],"sql":"b54d166028"}],"outcome":{"result":{"badgeAwards":[]}}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:badgeTypes:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:subjects:many","calls":[{"binds":["app.certified.badge.award","did:plc:abcdefghijklmnopqrstuvwy","at://did:plc:abcdefghijklmnopqrstuvwx/org.hypercerts.claim.activity/3kabcdefghija","at://did:plc:abcdefghijklmnopqrstuvwx/org.hypercerts.claim.activity/3kabcdefghijc",26],"sql":"ec5769b06c"}],"outcome":{"result":{"badgeAwards":[]}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:subjects:one","calls":[{"binds":["app.certified.badge.award","at://did:plc:abcdefghijklmnopqrstuvwx/org.hypercerts.claim.activity/3kabcdefghija",26],"sql":"07a40fe161"}],"outcome":{"result":{"badgeAwards":[]}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:subjects:one-scalar","calls":[{"binds":["app.certified.badge.award","at://did:plc:abcdefghijklmnopqrstuvwx/org.hypercerts.claim.activity/3kabcdefghija",26],"sql":"07a40fe161"}],"outcome":{"result":{"badgeAwards":[]}}} @@ -926,10 +926,10 @@ {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: responses entries must be strings"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each responses value must be accepted, rejected, or unanswered statuses"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: responses entries must be strings"}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:keyed-table","calls":[{"binds":["app.certified.badge.award","accepted",26],"sql":"fac78ac0ee"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:string-keyed-table","calls":[{"binds":["app.certified.badge.award",26],"sql":"b54d166028"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:sparse-table","calls":[{"binds":["app.certified.badge.award","accepted",26],"sql":"fac78ac0ee"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:sparse-table-from-2","calls":[{"binds":["app.certified.badge.award",26],"sql":"b54d166028"}],"outcome":{"result":{"badgeAwards":[]}}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: responses must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: responses must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: responses must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"array:responses:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: responses must use repeated query values"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:includeTotal=boolean:true","calls":[{"binds":["app.certified.badge.award",26],"sql":"3dfa9c7309"}],"outcome":{"result":{"badgeAwards":[],"totalCount":0}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:includeTotal=boolean:false","calls":[{"binds":["app.certified.badge.award",26],"sql":"eb4293ef0a"}],"outcome":{"result":{"badgeAwards":[]}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"filter:includeTotal=string:true","calls":[{"binds":["app.certified.badge.award",26],"sql":"3dfa9c7309"}],"outcome":{"result":{"badgeAwards":[],"totalCount":0}}} @@ -947,13 +947,13 @@ {"endpoint":"app.certified.badge.listBadgeAwards","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.badge.award","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.award/3kabcdefghijk",26],"sql":"5c69857418"}],"outcome":{"result":{"badgeAwards":[]}}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.badge.award","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.award/3kabcdefghijk",26],"sql":"5c69857418"}],"outcome":{"result":{"badgeAwards":[]}}} -{"endpoint":"app.certified.badge.listBadgeAwards","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.badge.award","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.award/3kabcdefghijk",26],"sql":"5c69857418"}],"outcome":{"result":{"badgeAwards":[]}}} +{"endpoint":"app.certified.badge.listBadgeAwards","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeAwards","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.badge.award","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.award/3kabcdefghijk",26],"sql":"5c69857418"}],"outcome":{"result":{"badgeAwards":[]}}} @@ -1055,10 +1055,10 @@ {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each authors value must be valid DIDs"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:keyed-table","calls":[{"binds":["app.certified.badge.definition","did:plc:abcdefghijklmnopqrstuvwx",26],"sql":"cf715d2ab7"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:string-keyed-table","calls":[{"binds":["app.certified.badge.definition",26],"sql":"089df365a0"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:sparse-table","calls":[{"binds":["app.certified.badge.definition","did:plc:abcdefghijklmnopqrstuvwx",26],"sql":"cf715d2ab7"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:sparse-table-from-2","calls":[{"binds":["app.certified.badge.definition",26],"sql":"089df365a0"}],"outcome":{"result":{"badgeDefinitions":[]}}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:authors:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"filter:badgeTypes:many","calls":[{"binds":["app.certified.badge.definition","volunteer","contributor","steward",26],"sql":"55bc2f4a15"}],"outcome":{"result":{"badgeDefinitions":[]}}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"filter:badgeTypes:one","calls":[{"binds":["app.certified.badge.definition","volunteer",26],"sql":"887630231f"}],"outcome":{"result":{"badgeDefinitions":[]}}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"filter:badgeTypes:one-scalar","calls":[{"binds":["app.certified.badge.definition","volunteer",26],"sql":"887630231f"}],"outcome":{"result":{"badgeDefinitions":[]}}} @@ -1070,10 +1070,10 @@ {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be strings"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be at most 100 UTF-8 bytes"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be strings"}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:keyed-table","calls":[{"binds":["app.certified.badge.definition","volunteer",26],"sql":"887630231f"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:string-keyed-table","calls":[{"binds":["app.certified.badge.definition",26],"sql":"089df365a0"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:sparse-table","calls":[{"binds":["app.certified.badge.definition","volunteer",26],"sql":"887630231f"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:sparse-table-from-2","calls":[{"binds":["app.certified.badge.definition",26],"sql":"089df365a0"}],"outcome":{"result":{"badgeDefinitions":[]}}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"array:badgeTypes:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"filter:all","calls":[{"binds":["app.certified.badge.definition","did:plc:abcdefghijklmnopqrstuvwx","did:plc:abcdefghijklmnopqrstuvwy","contributor","steward",26],"sql":"39e951d2e6"}],"outcome":{"result":{"badgeDefinitions":[]}}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:sortDirection=bad","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:sortDirection=ASC","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} @@ -1087,13 +1087,13 @@ {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.badge.definition","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijk",26],"sql":"2712d7dd78"}],"outcome":{"result":{"badgeDefinitions":[]}}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.badge.definition","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijk",26],"sql":"2712d7dd78"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.badge.definition","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijk",26],"sql":"2712d7dd78"}],"outcome":{"result":{"badgeDefinitions":[]}}} +{"endpoint":"app.certified.badge.listBadgeDefinitions","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeDefinitions","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.badge.definition","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijk",26],"sql":"2712d7dd78"}],"outcome":{"result":{"badgeDefinitions":[]}}} @@ -1199,13 +1199,13 @@ {"endpoint":"app.certified.badge.listBadgeResponses","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.badge.listBadgeResponses","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.badge.listBadgeResponses","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.badge.response","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.response/3kabcdefghijk",26],"sql":"bf4fe3b608"}],"outcome":{"result":{"badgeResponses":[]}}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.badge.response","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.response/3kabcdefghijk",26],"sql":"bf4fe3b608"}],"outcome":{"result":{"badgeResponses":[]}}} -{"endpoint":"app.certified.badge.listBadgeResponses","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.badge.response","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.response/3kabcdefghijk",26],"sql":"bf4fe3b608"}],"outcome":{"result":{"badgeResponses":[]}}} +{"endpoint":"app.certified.badge.listBadgeResponses","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.listBadgeResponses","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.badge.response","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.response/3kabcdefghijk",26],"sql":"bf4fe3b608"}],"outcome":{"result":{"badgeResponses":[]}}} @@ -1307,10 +1307,10 @@ {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each authors value must be valid DIDs"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:keyed-table","calls":[{"binds":["app.certified.badge.definition","did:plc:abcdefghijklmnopqrstuvwx","test",26],"sql":"7705bb084a"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:string-keyed-table","calls":[{"binds":["app.certified.badge.definition","test",26],"sql":"bf198ae94a"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:sparse-table","calls":[{"binds":["app.certified.badge.definition","did:plc:abcdefghijklmnopqrstuvwx","test",26],"sql":"7705bb084a"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:sparse-table-from-2","calls":[{"binds":["app.certified.badge.definition","test",26],"sql":"bf198ae94a"}],"outcome":{"result":{"badgeDefinitions":[]}}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:authors:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"filter:badgeTypes:many","calls":[{"binds":["app.certified.badge.definition","volunteer","contributor","steward","test",26],"sql":"04e237168d"}],"outcome":{"result":{"badgeDefinitions":[]}}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"filter:badgeTypes:one","calls":[{"binds":["app.certified.badge.definition","volunteer","test",26],"sql":"f144453bcf"}],"outcome":{"result":{"badgeDefinitions":[]}}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"filter:badgeTypes:one-scalar","calls":[{"binds":["app.certified.badge.definition","volunteer","test",26],"sql":"f144453bcf"}],"outcome":{"result":{"badgeDefinitions":[]}}} @@ -1322,10 +1322,10 @@ {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be strings"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be at most 100 UTF-8 bytes"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes entries must be strings"}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:keyed-table","calls":[{"binds":["app.certified.badge.definition","volunteer","test",26],"sql":"f144453bcf"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:string-keyed-table","calls":[{"binds":["app.certified.badge.definition","test",26],"sql":"bf198ae94a"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:sparse-table","calls":[{"binds":["app.certified.badge.definition","volunteer","test",26],"sql":"f144453bcf"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:sparse-table-from-2","calls":[{"binds":["app.certified.badge.definition","test",26],"sql":"bf198ae94a"}],"outcome":{"result":{"badgeDefinitions":[]}}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"array:badgeTypes:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: badgeTypes must use repeated query values"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"filter:all","calls":[{"binds":["app.certified.badge.definition","did:plc:abcdefghijklmnopqrstuvwx","did:plc:abcdefghijklmnopqrstuvwy","contributor","steward","test",26],"sql":"8e6d1e6347"}],"outcome":{"result":{"badgeDefinitions":[]}}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:sortDirection=bad","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:sortDirection=ASC","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} @@ -1339,13 +1339,13 @@ {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.badge.definition","test","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijk",26],"sql":"9a5987f560"}],"outcome":{"result":{"badgeDefinitions":[]}}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.badge.definition","test","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijk",26],"sql":"9a5987f560"}],"outcome":{"result":{"badgeDefinitions":[]}}} -{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.badge.definition","test","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijk",26],"sql":"9a5987f560"}],"outcome":{"result":{"badgeDefinitions":[]}}} +{"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.badge.searchBadgeDefinitions","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.badge.definition","test","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.badge.definition/3kabcdefghijk",26],"sql":"9a5987f560"}],"outcome":{"result":{"badgeDefinitions":[]}}} @@ -1885,13 +1885,13 @@ {"endpoint":"app.certified.graph.listActorFollowers","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.graph.listActorFollowers","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.graph.listActorFollowers","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.graph.follow","did:plc:abcdefghijklmnopqrstuvwx","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.graph.follow/3kabcdefghijk",26],"sql":"a4f35cd109"}],"outcome":{"result":{"followers":[],"totalCount":0}}} {"endpoint":"app.certified.graph.listActorFollowers","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.graph.follow","did:plc:abcdefghijklmnopqrstuvwx","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.graph.follow/3kabcdefghijk",26],"sql":"a4f35cd109"}],"outcome":{"result":{"followers":[],"totalCount":0}}} -{"endpoint":"app.certified.graph.listActorFollowers","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.graph.follow","did:plc:abcdefghijklmnopqrstuvwx","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.graph.follow/3kabcdefghijk",26],"sql":"a4f35cd109"}],"outcome":{"result":{"followers":[],"totalCount":0}}} +{"endpoint":"app.certified.graph.listActorFollowers","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowers","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.graph.follow","did:plc:abcdefghijklmnopqrstuvwx","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.graph.follow/3kabcdefghijk",26],"sql":"a4f35cd109"}],"outcome":{"result":{"followers":[],"totalCount":0}}} @@ -1994,13 +1994,13 @@ {"endpoint":"app.certified.graph.listActorFollowing","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.graph.listActorFollowing","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.graph.listActorFollowing","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.graph.follow","did:plc:abcdefghijklmnopqrstuvwx","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.graph.follow/3kabcdefghijk",26],"sql":"b224c5782a"}],"outcome":{"result":{"following":[],"totalCount":0}}} {"endpoint":"app.certified.graph.listActorFollowing","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.graph.follow","did:plc:abcdefghijklmnopqrstuvwx","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.graph.follow/3kabcdefghijk",26],"sql":"b224c5782a"}],"outcome":{"result":{"following":[],"totalCount":0}}} -{"endpoint":"app.certified.graph.listActorFollowing","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.graph.follow","did:plc:abcdefghijklmnopqrstuvwx","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.graph.follow/3kabcdefghijk",26],"sql":"b224c5782a"}],"outcome":{"result":{"following":[],"totalCount":0}}} +{"endpoint":"app.certified.graph.listActorFollowing","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.graph.listActorFollowing","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.graph.follow","did:plc:abcdefghijklmnopqrstuvwx","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.graph.follow/3kabcdefghijk",26],"sql":"b224c5782a"}],"outcome":{"result":{"following":[],"totalCount":0}}} @@ -2421,10 +2421,10 @@ {"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: actors entries must be strings"}} {"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: actors[2] must be valid DIDs"}} {"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: actors entries must be strings"}} -{"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:keyed-table","calls":[{"binds":["app.certified.link.evm","did:plc:abcdefghijklmnopqrstuvwx",26],"sql":"269699e131"}],"outcome":{"result":{"evmLinks":[]}}} -{"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:string-keyed-table","calls":[{"binds":["app.certified.link.evm",26],"sql":"1d0659e810"}],"outcome":{"result":{"evmLinks":[]}}} -{"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:sparse-table","calls":[{"binds":["app.certified.link.evm","did:plc:abcdefghijklmnopqrstuvwx",26],"sql":"269699e131"}],"outcome":{"result":{"evmLinks":[]}}} -{"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:sparse-table-from-2","calls":[{"binds":["app.certified.link.evm",26],"sql":"1d0659e810"}],"outcome":{"result":{"evmLinks":[]}}} +{"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: actors must use repeated query values"}} +{"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: actors must use repeated query values"}} +{"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: actors must use repeated query values"}} +{"endpoint":"app.certified.link.listEvmLinks","case":"array:actors:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: actors must use repeated query values"}} {"endpoint":"app.certified.link.listEvmLinks","case":"filter:addresses:many","calls":[{"binds":["app.certified.link.evm","0x1111111111111111111111111111111111111111","0x2222222222222222222222222222222222222222","0x3333333333333333333333333333333333333333",26],"sql":"7f03b386ae"}],"outcome":{"result":{"evmLinks":[]}}} {"endpoint":"app.certified.link.listEvmLinks","case":"filter:addresses:one","calls":[{"binds":["app.certified.link.evm","0x1111111111111111111111111111111111111111",26],"sql":"99c5929723"}],"outcome":{"result":{"evmLinks":[]}}} {"endpoint":"app.certified.link.listEvmLinks","case":"filter:addresses:one-scalar","calls":[{"binds":["app.certified.link.evm","0x1111111111111111111111111111111111111111",26],"sql":"99c5929723"}],"outcome":{"result":{"evmLinks":[]}}} @@ -2436,10 +2436,10 @@ {"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: addresses entries must be strings"}} {"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: addresses[2] must be a 0x-prefixed 40-digit hexadecimal EVM address"}} {"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: addresses entries must be strings"}} -{"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:keyed-table","calls":[{"binds":["app.certified.link.evm","0x1111111111111111111111111111111111111111",26],"sql":"99c5929723"}],"outcome":{"result":{"evmLinks":[]}}} -{"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:string-keyed-table","calls":[{"binds":["app.certified.link.evm",26],"sql":"1d0659e810"}],"outcome":{"result":{"evmLinks":[]}}} -{"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:sparse-table","calls":[{"binds":["app.certified.link.evm","0x1111111111111111111111111111111111111111",26],"sql":"99c5929723"}],"outcome":{"result":{"evmLinks":[]}}} -{"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:sparse-table-from-2","calls":[{"binds":["app.certified.link.evm",26],"sql":"1d0659e810"}],"outcome":{"result":{"evmLinks":[]}}} +{"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: addresses must use repeated query values"}} +{"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: addresses must use repeated query values"}} +{"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: addresses must use repeated query values"}} +{"endpoint":"app.certified.link.listEvmLinks","case":"array:addresses:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: addresses must use repeated query values"}} {"endpoint":"app.certified.link.listEvmLinks","case":"filter:all","calls":[{"binds":["app.certified.link.evm","did:plc:abcdefghijklmnopqrstuvwx","did:plc:abcdefghijklmnopqrstuvwy","0x2222222222222222222222222222222222222222","0x3333333333333333333333333333333333333333",26],"sql":"c9e349830f"}],"outcome":{"result":{"evmLinks":[]}}} {"endpoint":"app.certified.link.listEvmLinks","case":"error:sortDirection=bad","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} {"endpoint":"app.certified.link.listEvmLinks","case":"error:sortDirection=ASC","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} @@ -2459,7 +2459,7 @@ {"endpoint":"app.certified.link.listEvmLinks","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.link.listEvmLinks","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.link.evm","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.link.evm/3kabcdefghijk",26],"sql":"9d1064a743"}],"outcome":{"result":{"evmLinks":[]}}} {"endpoint":"app.certified.link.listEvmLinks","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.link.evm","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.link.evm/3kabcdefghijk",26],"sql":"9d1064a743"}],"outcome":{"result":{"evmLinks":[]}}} -{"endpoint":"app.certified.link.listEvmLinks","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.link.evm","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.link.evm/3kabcdefghijk",26],"sql":"9d1064a743"}],"outcome":{"result":{"evmLinks":[]}}} +{"endpoint":"app.certified.link.listEvmLinks","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.link.listEvmLinks","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.link.listEvmLinks","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.link.listEvmLinks","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.link.evm","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.link.evm/3kabcdefghijk",26],"sql":"9d1064a743"}],"outcome":{"result":{"evmLinks":[]}}} @@ -2561,10 +2561,10 @@ {"endpoint":"app.certified.location.listLocations","case":"array:authors:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} {"endpoint":"app.certified.location.listLocations","case":"array:authors:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each authors value must be valid DIDs"}} {"endpoint":"app.certified.location.listLocations","case":"array:authors:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} -{"endpoint":"app.certified.location.listLocations","case":"array:authors:keyed-table","calls":[{"binds":["app.certified.location","did:plc:abcdefghijklmnopqrstuvwx",26],"sql":"cf715d2ab7"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:authors:string-keyed-table","calls":[{"binds":["app.certified.location",26],"sql":"089df365a0"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:authors:sparse-table","calls":[{"binds":["app.certified.location","did:plc:abcdefghijklmnopqrstuvwx",26],"sql":"cf715d2ab7"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:authors:sparse-table-from-2","calls":[{"binds":["app.certified.location",26],"sql":"089df365a0"}],"outcome":{"result":{"locations":[]}}} +{"endpoint":"app.certified.location.listLocations","case":"array:authors:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:authors:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:authors:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:authors:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} {"endpoint":"app.certified.location.listLocations","case":"filter:uris:many","calls":[{"binds":["app.certified.location","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghija","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghijb","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghijc",26],"sql":"ca16d794fb"}],"outcome":{"result":{"locations":[]}}} {"endpoint":"app.certified.location.listLocations","case":"filter:uris:one","calls":[{"binds":["app.certified.location","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghija",26],"sql":"8d97cb081a"}],"outcome":{"result":{"locations":[]}}} {"endpoint":"app.certified.location.listLocations","case":"filter:uris:one-scalar","calls":[{"binds":["app.certified.location","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghija",26],"sql":"8d97cb081a"}],"outcome":{"result":{"locations":[]}}} @@ -2576,10 +2576,10 @@ {"endpoint":"app.certified.location.listLocations","case":"array:uris:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: uris entries must be strings"}} {"endpoint":"app.certified.location.listLocations","case":"array:uris:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each uris value must be full app.certified.location AT-URIs with DID authorities"}} {"endpoint":"app.certified.location.listLocations","case":"array:uris:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: uris entries must be strings"}} -{"endpoint":"app.certified.location.listLocations","case":"array:uris:keyed-table","calls":[{"binds":["app.certified.location","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghija",26],"sql":"8d97cb081a"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:uris:string-keyed-table","calls":[{"binds":["app.certified.location",26],"sql":"089df365a0"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:uris:sparse-table","calls":[{"binds":["app.certified.location","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghija",26],"sql":"8d97cb081a"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:uris:sparse-table-from-2","calls":[{"binds":["app.certified.location",26],"sql":"089df365a0"}],"outcome":{"result":{"locations":[]}}} +{"endpoint":"app.certified.location.listLocations","case":"array:uris:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: uris must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:uris:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: uris must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:uris:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: uris must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:uris:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: uris must use repeated query values"}} {"endpoint":"app.certified.location.listLocations","case":"filter:locationTypes:many","calls":[{"binds":["app.certified.location","coordinate-decimal","geojson","address",26],"sql":"03715b3085"}],"outcome":{"result":{"locations":[]}}} {"endpoint":"app.certified.location.listLocations","case":"filter:locationTypes:one","calls":[{"binds":["app.certified.location","coordinate-decimal",26],"sql":"bb7a1812ec"}],"outcome":{"result":{"locations":[]}}} {"endpoint":"app.certified.location.listLocations","case":"filter:locationTypes:one-scalar","calls":[{"binds":["app.certified.location","coordinate-decimal",26],"sql":"bb7a1812ec"}],"outcome":{"result":{"locations":[]}}} @@ -2591,10 +2591,10 @@ {"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: locationTypes entries must be strings"}} {"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: locationTypes entries must be at most 20 UTF-8 bytes"}} {"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: locationTypes entries must be strings"}} -{"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:keyed-table","calls":[{"binds":["app.certified.location","coordinate-decimal",26],"sql":"bb7a1812ec"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:string-keyed-table","calls":[{"binds":["app.certified.location",26],"sql":"089df365a0"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:sparse-table","calls":[{"binds":["app.certified.location","coordinate-decimal",26],"sql":"bb7a1812ec"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:sparse-table-from-2","calls":[{"binds":["app.certified.location",26],"sql":"089df365a0"}],"outcome":{"result":{"locations":[]}}} +{"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: locationTypes must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: locationTypes must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: locationTypes must use repeated query values"}} +{"endpoint":"app.certified.location.listLocations","case":"array:locationTypes:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: locationTypes must use repeated query values"}} {"endpoint":"app.certified.location.listLocations","case":"filter:all","calls":[{"binds":["app.certified.location","did:plc:abcdefghijklmnopqrstuvwx","did:plc:abcdefghijklmnopqrstuvwy","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghijb","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghijc","coordinate-decimal","geojson",26],"sql":"39d1ecf7da"}],"outcome":{"result":{"locations":[]}}} {"endpoint":"app.certified.location.listLocations","case":"error:sortDirection=bad","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} {"endpoint":"app.certified.location.listLocations","case":"error:sortDirection=ASC","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} @@ -2608,13 +2608,13 @@ {"endpoint":"app.certified.location.listLocations","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"app.certified.location.listLocations","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"app.certified.location.listLocations","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"app.certified.location.listLocations","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"app.certified.location.listLocations","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.location.listLocations","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"app.certified.location.listLocations","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once"}} {"endpoint":"app.certified.location.listLocations","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.location.listLocations","case":"cursor:length-at-cap","calls":[{"binds":["app.certified.location","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghijk",26],"sql":"2712d7dd78"}],"outcome":{"result":{"locations":[]}}} {"endpoint":"app.certified.location.listLocations","case":"cursor:length-below-cap","calls":[{"binds":["app.certified.location","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghijk",26],"sql":"2712d7dd78"}],"outcome":{"result":{"locations":[]}}} -{"endpoint":"app.certified.location.listLocations","case":"cursor:length-above-cap","calls":[{"binds":["app.certified.location","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghijk",26],"sql":"2712d7dd78"}],"outcome":{"result":{"locations":[]}}} +{"endpoint":"app.certified.location.listLocations","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.location.listLocations","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.location.listLocations","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"app.certified.location.listLocations","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["app.certified.location","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/app.certified.location/3kabcdefghijk",26],"sql":"2712d7dd78"}],"outcome":{"result":{"locations":[]}}} @@ -4524,10 +4524,10 @@ {"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: each authors value must be valid DIDs"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: authors entries must be strings"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated string query parameters"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated string query parameters"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated string query parameters"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated string query parameters"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:authors:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: authors must use repeated query values"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"filter:hasOrganizationRecord=boolean:true","calls":[{"binds":["org.hypercerts.entity.feature",26],"sql":"1f264cba3c"}],"outcome":{"result":{"features":[]}}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"filter:hasOrganizationRecord=boolean:false","calls":[{"binds":["org.hypercerts.entity.feature",26],"sql":"92fa39766a"}],"outcome":{"result":{"features":[]}}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"filter:hasOrganizationRecord=string:true","calls":[{"binds":["org.hypercerts.entity.feature",26],"sql":"1f264cba3c"}],"outcome":{"result":{"features":[]}}} @@ -4543,10 +4543,10 @@ {"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:non-string-item","calls":[],"outcome":{"error":"InvalidRequest: types entries must be strings"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:oversize-item","calls":[],"outcome":{"error":"InvalidRequest: types entries must be at most 64 UTF-8 bytes"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:nested-array-item","calls":[],"outcome":{"error":"InvalidRequest: types entries must be strings"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: types must use repeated string query parameters"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: types must use repeated string query parameters"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: types must use repeated string query parameters"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: types must use repeated string query parameters"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:keyed-table","calls":[],"outcome":{"error":"InvalidRequest: types must use repeated query values"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:string-keyed-table","calls":[],"outcome":{"error":"InvalidRequest: types must use repeated query values"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:sparse-table","calls":[],"outcome":{"error":"InvalidRequest: types must use repeated query values"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"array:types:sparse-table-from-2","calls":[],"outcome":{"error":"InvalidRequest: types must use repeated query values"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"filter:all","calls":[{"binds":["org.hypercerts.entity.feature","did:plc:abcdefghijklmnopqrstuvwx","did:plc:abcdefghijklmnopqrstuvwy","project","portfolio",26],"sql":"1a4336693f"}],"outcome":{"result":{"features":[]}}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"error:sortDirection=bad","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"error:sortDirection=ASC","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must be 'asc' or 'desc'"}} @@ -4560,13 +4560,13 @@ {"endpoint":"org.hypercerts.entity.listFeatures","case":"error:limit=array","calls":[],"outcome":{"error":"InvalidRequest: limit must occur once"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"error:sortDirection=array","calls":[],"outcome":{"error":"InvalidRequest: sortDirection must occur once"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"error:cursor:non-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"error:cursor:empty","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"error:cursor:hex-non-json","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed or belongs to another sortDirection"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"error:cursor:array","calls":[],"outcome":{"error":"InvalidRequest: cursor must occur once as a string"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"error:cursor:uppercase-hex","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"cursor:length-at-cap","calls":[{"binds":["org.hypercerts.entity.feature","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/org.hypercerts.entity.feature/3kabcdefghijk",26],"sql":"d8dea693a3"}],"outcome":{"result":{"features":[]}}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"cursor:length-below-cap","calls":[{"binds":["org.hypercerts.entity.feature","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/org.hypercerts.entity.feature/3kabcdefghijk",26],"sql":"d8dea693a3"}],"outcome":{"result":{"features":[]}}} -{"endpoint":"org.hypercerts.entity.listFeatures","case":"cursor:length-above-cap","calls":[{"binds":["org.hypercerts.entity.feature","2025-01-01T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/org.hypercerts.entity.feature/3kabcdefghijk",26],"sql":"d8dea693a3"}],"outcome":{"result":{"features":[]}}} +{"endpoint":"org.hypercerts.entity.listFeatures","case":"cursor:length-above-cap","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"datetime:cursor-t:month-13","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"datetime:cursor-t:feb-30","calls":[],"outcome":{"error":"InvalidRequest: cursor is malformed"}} {"endpoint":"org.hypercerts.entity.listFeatures","case":"datetime:cursor-t:leap-2024-valid","calls":[{"binds":["org.hypercerts.entity.feature","2024-02-29T00:00:00Z","at://did:plc:abcdefghijklmnopqrstuvwx/org.hypercerts.entity.feature/3kabcdefghijk",26],"sql":"d8dea693a3"}],"outcome":{"result":{"features":[]}}} diff --git a/happyview-modules/tests/unit/tooling/listContributorInformation.test.js b/happyview-modules/tests/unit/tooling/listContributorInformation.test.js index d7e89c57..e2aea216 100644 --- a/happyview-modules/tests/unit/tooling/listContributorInformation.test.js +++ b/happyview-modules/tests/unit/tooling/listContributorInformation.test.js @@ -11,6 +11,7 @@ const read = (relative) => readFile(path.resolve(root, relative), "utf8"); test("listContributorInformation filters repeated authors and resumes in the selected order", async () => { const sources = await Promise.all([ read("lua/shared/query.lua"), + read("lua/shared/queryArray.lua"), read("lua/shared/didValidation.lua"), read("lua/shared/recordIdentifier.lua"), read("lua/shared/contributorInformationValidation.lua"), diff --git a/happyview-modules/tooling/shared-helpers.registry.json b/happyview-modules/tooling/shared-helpers.registry.json index 97d9e36f..3c79a8ce 100644 --- a/happyview-modules/tooling/shared-helpers.registry.json +++ b/happyview-modules/tooling/shared-helpers.registry.json @@ -105,9 +105,8 @@ { "id": "repeated-query-array", "description": "repeated query parameter (array) parsing", - "unowned": "each endpoint has its own; add a shared parser in lua/shared and register it before adding another", "lookalikes": ["(^|_)array(_values)?$"], - "homes": [] + "homes": ["lua/shared/queryArray.lua"] }, { "id": "record-view", @@ -140,398 +139,152 @@ "file": "lua/shared/acknowledgementList.lua", "family": "datetime-validation", "symbol": "valid_cursor_timestamp", - "reason": "Existing cursor timestamp check with its own rules; kept to avoid a behavior change." - }, - { - "file": "lua/shared/acknowledgementList.lua", - "family": "repeated-query-array", - "symbol": "acknowledgement_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + "reason": "Stricter than valid_datetime: requires exactly six fractional digits, because acknowledgement cursors are written from to_char(...US) timestamps. Passed to decode_record_cursor as its timestamp check." }, { "file": "lua/shared/activityList.lua", "family": "record-identifier", "symbol": "at-uri-pattern", - "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows.", + "reason": "Not Lua parsing: the pattern sits inside a SQL substring(... from '^at://...') that extracts the DID authority in the database. The inline rule cannot tell SQL text from Lua code.", "count": 2 }, - { - "file": "lua/shared/activityList.lua", - "family": "repeated-query-array", - "symbol": "activity_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, { "file": "lua/shared/activityProjection.lua", "family": "record-view", "symbol": "activity_projection_record_view", - "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." - }, - { - "file": "lua/shared/actorFollowList.lua", - "family": "list-cursor", - "symbol": "cursor_decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/shared/actorFollowList.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/shared/attachmentList.lua", - "family": "repeated-query-array", - "symbol": "attachment_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + "reason": "Takes a nullable flag: sidecars (contributors) omit indexedAt when missing while the top-level activity emits JSON null, which one record_view or record_view_omitting_indexed_at cannot express." }, { "file": "lua/shared/collectionItems.lua", "family": "list-cursor", "symbol": "collection_items_cursor_decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/shared/collectionList.lua", - "family": "repeated-query-array", - "symbol": "collection_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + "reason": "Position cursor {v,u,i} with no direction or timestamp and its own error message (\"belongs to another collection\"). It already shares the hex prologue through decode_hex_cursor_token; only the shape check is local." }, { "file": "lua/shared/evaluation.lua", "family": "repeated-query-array", "symbol": "evaluation_evaluator_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/shared/evaluationList.lua", - "family": "repeated-query-array", - "symbol": "evaluation_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + "reason": "Not a query parser: it checks that an indexed evaluation record field is a list. The name only resembles the repeated-parameter parsers." }, { "file": "lua/shared/feedActorReactions.lua", "family": "record-view", "symbol": "feed_actor_reaction_record_view", - "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." - }, - { - "file": "lua/shared/fundingReceiptList.lua", - "family": "repeated-query-array", - "symbol": "funding_receipt_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/shared/organizationList.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/shared/organizationList.lua", - "family": "repeated-query-array", - "symbol": "array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/shared/profileList.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + "reason": "Adds prefix columns and strict validation of the row on top of record_view, which it already calls; the wrapper is the endpoint-specific part." }, { "file": "lua/shared/recentFollows.lua", "family": "list-cursor", "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + "reason": "The cursor carries the caller-supplied before datetime (no length bound); the shared 8192-character cap could reject a cursor the API issued." }, { "file": "lua/shared/recentFollows.lua", "family": "list-cursor", "symbol": "recent_cursor_decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + "reason": "The cursor carries the caller-supplied before datetime (no length bound), so the shared 8192-character cap could reject a cursor the API itself issued. Also has its own shape {v,t,u,b} and messages." }, { "file": "lua/shared/recentFollows.lua", "family": "record-view", "symbol": "recent_record_view", - "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." - }, - { - "file": "lua/shared/workscopeTagList.lua", - "family": "repeated-query-array", - "symbol": "workscope_tag_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/src/listBadgeAwards.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listBadgeAwards.lua", - "family": "list-cursor", - "symbol": "decode_badge_award_cursor", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listBadgeAwards.lua", - "family": "repeated-query-array", - "symbol": "array_values", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/src/listBadgeDefinitions.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listBadgeDefinitions.lua", - "family": "list-cursor", - "symbol": "decode_badge_definition_cursor", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listBadgeDefinitions.lua", - "family": "repeated-query-array", - "symbol": "badge_definition_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/src/listBadgeResponses.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listBadgeResponses.lua", - "family": "list-cursor", - "symbol": "decode_badge_response_cursor", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listContributorInformation.lua", - "family": "repeated-query-array", - "symbol": "contributor_information_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/src/listEvmLinks.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listEvmLinks.lua", - "family": "list-cursor", - "symbol": "decode_evm_link_cursor", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listEvmLinks.lua", - "family": "repeated-query-array", - "symbol": "array_values", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/src/listFeatures.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listFeatures.lua", - "family": "list-cursor", - "symbol": "feature_cursor_decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + "reason": "Wraps the JSON decode in pcall so a corrupt indexed record raises RecentFollowsQueryFailed instead of a generic error; record_view has no such error contract." }, { "file": "lua/src/listFeatures.lua", "family": "query-params", "symbol": "occur-once-message", - "reason": "Existing endpoint-local copy of the shared query helpers; kept to avoid a behavior change. Use query.lua helpers instead." - }, - { - "file": "lua/src/listFeatures.lua", - "family": "repeated-query-array", - "symbol": "feature_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/src/listLocations.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/listMeasurements.lua", - "family": "repeated-query-array", - "symbol": "measurement_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." - }, - { - "file": "lua/src/listRights.lua", - "family": "repeated-query-array", - "symbol": "rights_list_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + "reason": "listFeatures reads cursor from params directly and rejects anything that is not a string (\"cursor must occur once as a string\"), including numbers, which scalar() accepts and stringifies. Moving to scalar() would change which inputs are rejected and the message." }, { "file": "lua/src/listVocabTags.lua", "family": "list-cursor", "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/searchBadgeDefinitions.lua", - "family": "list-cursor", - "symbol": "cursor-hex-decode", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/searchBadgeDefinitions.lua", - "family": "list-cursor", - "symbol": "decode_badge_definition_cursor", - "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." - }, - { - "file": "lua/src/searchBadgeDefinitions.lua", - "family": "repeated-query-array", - "symbol": "badge_definition_array", - "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + "reason": "The cursor carries the author filter (f), so its size is not bounded by an AT-URI; the shared 8192-character cap could reject a cursor the API issued." }, { "file": "lua/shared/actorFollow.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/shared/location.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/shared/organization.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." - }, - { - "file": "lua/shared/organizationList.lua", - "family": "shared-helper", - "symbol": "cursor_decode", - "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/shared/profile.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." - }, - { - "file": "lua/shared/profileList.lua", - "family": "shared-helper", - "symbol": "array", - "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." - }, - { - "file": "lua/shared/profileList.lua", - "family": "shared-helper", - "symbol": "cursor_decode", - "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/src/getBadgeAward.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/src/getBadgeDefinition.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/src/getBadgeResponse.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/src/getVocabTag.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." - }, - { - "file": "lua/src/listBadgeAwards.lua", - "family": "shared-helper", - "symbol": "valid_badge_definition_uri", - "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/src/listBadgeAwards.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/src/listBadgeDefinitions.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/src/listBadgeResponses.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." - }, - { - "file": "lua/src/listLocations.lua", - "family": "shared-helper", - "symbol": "array", - "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." - }, - { - "file": "lua/src/listLocations.lua", - "family": "shared-helper", - "symbol": "add_in", - "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." - }, - { - "file": "lua/src/listLocations.lua", - "family": "shared-helper", - "symbol": "cursor_decode", - "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { - "file": "lua/src/listMeasurements.lua", + "file": "lua/src/listVocabTags.lua", "family": "shared-helper", - "symbol": "bind_values", - "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + "symbol": "query", + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { - "file": "lua/src/listVocabTags.lua", + "file": "lua/src/searchBadgeDefinitions.lua", "family": "shared-helper", "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "Module-local database wrapper `query(sql, values)` that raises that module's own *QueryFailed error name and message, so it is not one shared function. It only shares a name with the others." }, { "file": "lua/src/listVocabTags.lua", "family": "list-cursor", "symbol": "decode_vocab_tag_cursor", - "reason": "Pending A1 in the follow-up PR: this decoder has no 8192-character cap and an empty cursor gets a different message; its cursor also carries the author filter. Renamed from decode_cursor so it no longer collides with the shared helper." - }, - { - "file": "lua/src/searchBadgeDefinitions.lua", - "family": "shared-helper", - "symbol": "query", - "reason": "Per-module query entry point that shares a name; not a reusable helper." + "reason": "The cursor also carries the author filter ({v,d,f,t,u}), so its size is not bounded by an AT-URI and it cannot take the shared 8192-character cap without rejecting cursors the API issued. Renamed from decode_cursor so it no longer collides with the shared helper name." } ], "allowlistNote": "The allowlist is a baseline of copies that existed when the lint was added. It is not approval to add more: new entries need a specific reason, and count must match the occurrences exactly." diff --git a/packages/api/src/lexicons/org/hypercerts/entity/listFeatures.defs.ts b/packages/api/src/lexicons/org/hypercerts/entity/listFeatures.defs.ts index c732399c..d05d4b6e 100644 --- a/packages/api/src/lexicons/org/hypercerts/entity/listFeatures.defs.ts +++ b/packages/api/src/lexicons/org/hypercerts/entity/listFeatures.defs.ts @@ -11,7 +11,7 @@ type $nsid = typeof $nsid; export { $nsid }; -export const $params = /*#__PURE__*/ l.params({"authors":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.array(/*#__PURE__*/ l.string({"format":"did"}), {"maxLength":100})),"hasOrganizationRecord":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),"types":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.array(/*#__PURE__*/ l.string({"maxLength":64}), {"maxLength":100})),"sortDirection":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.withDefault(/*#__PURE__*/ l.enum(["asc","desc"]), "desc")),"limit":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.withDefault(/*#__PURE__*/ l.integer({"minimum":1,"maximum":100}), 25)),"cursor":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({"maxLength":32768}))}); +export const $params = /*#__PURE__*/ l.params({"authors":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.array(/*#__PURE__*/ l.string({"format":"did"}), {"maxLength":100})),"hasOrganizationRecord":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),"types":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.array(/*#__PURE__*/ l.string({"maxLength":64}), {"maxLength":100})),"sortDirection":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.withDefault(/*#__PURE__*/ l.enum(["asc","desc"]), "desc")),"limit":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.withDefault(/*#__PURE__*/ l.integer({"minimum":1,"maximum":100}), 25)),"cursor":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({"maxLength":8192}))}); export type $Params = l.InferOutput;