Schema.isPowerOf
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- backend-api-design
Research direction
A linked pull request, #9006, is already open for this feature. Review the issue's proposed isPowerOf implementation and its toJsonSchema enum approach, then compare them with the existing isMultipleOf implementation mentioned in the issue. Done means the linked change provides the requested power-of validation and an agreed JSON Schema representation.
Written by the indexing model from the issue text.
Description
What is the problem this feature would solve?
So, I wanted to create a PasswordHashingMemoryCost schema, one of the checks i need is, isPowerOf(2) however there's no isPowerOf only isMultiplyOf
What is the feature you are proposing to solve the problem?
using isMultipleOf as reference I came up with this:
export function isPowerOf(
base: number,
annotations?: Annotations.Filter
): SchemaAST.Filter<number> {
if (!globalThis.Number.isInteger(base) || base < 2) {
throw new globalThis.RangeError(
`Expected an integer greater than or equal to 2, got ${globalThis.String(base)}`
)
}
return makeFilter(
(input: number) => {
if (!globalThis.Number.isSafeInteger(input) || input < 1) {
return false
}
while (input % base === 0) {
input = input / base
}
return input === 1
},
{
expected: `a value that is a power of ${base}`,
representation: {
id: "effect/schema/isPowerOf",
payload: { base }
},
toJsonSchema: () => ({
enum: globalThis.Array.from(
{
length: globalThis.Math.floor(
globalThis.Math.log(globalThis.Number.MAX_SAFE_INTEGER) / globalThis.Math.log(base)
) + 2
},
(_, k) => base ** k
).filter(globalThis.Number.isSafeInteger)
}),
toCode: () => ({ runtime: `Schema.isPowerOf(${format(base)})` }),
...annotations
}
)
}
for toJsonSchema I wan't quite sure because json schema doesn't have a "power of" check, so I thought of using an enum, which even in the worst case (base = 2) would "only" have 53 values
What alternatives have you considered?
an anum, writing the values manually
- Dominant language
- TypeScript
- Stars
- 16.7k
- Forks
- 808
- Avg merge
- 10h 38m
- Merged PRs (30d)
- 495
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Effect-TS/effect
-
BrowserWorkerRunner: port finalizer throws when the worker global has no close() (Bun)Possibly taken @santiago-ramos-02 claimed this 11 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Effect-TS/effect#8635 · 3 comments ·
Maintainers usually reply within 1 day
-
Support {self: this} for fnUntracedMay be free again @ArjunCodess claimed this 22 days ago, and no pull request is open. Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Effect-TS/effect#8101 · 1 comment ·
Maintainers usually reply within 1 day
-
add Effect-native McpClientPossibly taken @lloydrichards claimed this 5 days ago. Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 8/100
Effect-TS/effect#8912 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 28/100
Maintainers usually reply within 1 day
All issues in Effect-TS/effect
Similar issues
-
by: ai-assisted frontend good-for: new-member spike
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Northeastern-Electric-Racing/Argos#847 ·
Maintainers usually reply within 4 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
SignalK/freeboard-sk#990 ·
Maintainers usually reply within 1 day
-
[missing-inheritance] audit review (1 preset)Possibly taken @github-actions claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 82/100
osmberlin/tagging-schema-browser#363 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Albert-Weasker/niubigeo#205 ·
Maintainers usually reply within 1 day
-
area/frontend area/v2 kind/bug priority/needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
kubeflow/notebooks#1498 · 1 comment ·
Maintainers usually reply within 1 day