PIat
PIat
Explore posts from servers
BABetter Auth
Created by PIat on 4/7/2025 in #help
Team metadata
Hello! I am using the metadata field in Organizations to organize them using ids, since the app is intenationalized. The team schema, however, is missing a metadata field. How can I add metadata to it? Any help would be appreciated!
2 replies
NNovu
Created by PIat on 4/2/2025 in #💬│support
Skeleton in editor
No description
24 replies
BABetter Auth
Created by PIat on 1/23/2025 in #help
Slow API
Hello! When I try try create an organization and update it immediately, the update either doesn't run at all or it takes about 20 seconds. What is the reason for this slowdown?
17 replies
PPrisma
Created by PIat on 1/2/2025 in #help-and-questions
Using a JSON field as an id
Hello! I want to cache API results in the database and I was wondering if it'd be possible to use the id in the JSON field as an id, perhaps through @@id or some client extension?
4 replies
BABetter Auth
Created by PIat on 12/26/2024 in #help
Organization access control
Hello! In my app there are different articles which can have different languages, countries and cities. Only users with the correct list of permissions should be able to edit a post. Would every country-city-language pair have to be its own organization? Or is there a better way to do this? What about sharing editing access with another user? Would there have to be a new organization for each post? https://www.better-auth.com/docs/plugins/organization#list-users-organizations
7 replies
Aarktype
Created by PIat on 10/9/2024 in #questions
Type definitions must be strings or objects (was undefined)
Hello! When importing a module that is using Arktype, I get the error Type definitions must be strings or objects (was undefined). I am not sure what it means. What should I be looking for to solve it?
18 replies
Aarktype
Created by PIat on 10/8/2024 in #questions
Conform to an existing type
Hello! Is there a way to force a def to conform to an existing typescript type?
export const chatDef = type({
id: 'number',
chatType: "private' | 'public'",
title: 'string',
username: 'string'
// force this
}) satisfies Pick<Jsonify<Chat>, 'id' | 'chatType' | 'title' | 'username'>
export const chatDef = type({
id: 'number',
chatType: "private' | 'public'",
title: 'string',
username: 'string'
// force this
}) satisfies Pick<Jsonify<Chat>, 'id' | 'chatType' | 'title' | 'username'>
29 replies
Aarktype
Created by PIat on 10/1/2024 in #questions
Node of kind optional is not valid as a required definition
Hello! Whenever I use a type with an optional key with a default value like this:
const def = type({
'agree?': 'boolean = true',
})
const def = type({
'agree?': 'boolean = true',
})
I get the error Node of kind optional is not valid as a required definition. What could it mean? Note that I'm also updating the type via map, but removing that mapping appeared to have no effect so far. Removing the default value throws no error
42 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
ParseError: undefined must be a PropertyKey or stringifyNonKey must be passed to options
Hello! When key isn't provided in the .map function, the above error is thrown. Not working code:
const mapTypes = <T extends typeof typee>(t: T) =>
t.map((prop) => {
const key = prop.key
const value = prop.value

if (value.extends(type.number)) {
return [prop, { value: value.or('string.numeric.parse') }]
}

if (value.extends('boolean')) {
return [prop, { value: value.or(['string', '=>', (v) => v === 'on']) }]
}

return prop
})
const mapTypes = <T extends typeof typee>(t: T) =>
t.map((prop) => {
const key = prop.key
const value = prop.value

if (value.extends(type.number)) {
return [prop, { value: value.or('string.numeric.parse') }]
}

if (value.extends('boolean')) {
return [prop, { value: value.or(['string', '=>', (v) => v === 'on']) }]
}

return prop
})
Working code (simply added key to return object):
const mapTypes = <T extends typeof typee>(t: T) =>
t.map((prop) => {
const key = prop.key
const value = prop.value

if (value.extends(type.number)) {
return [prop, { key, value: value.or('string.numeric.parse') }]
}

if (value.extends('boolean')) {
return [
prop,
{ key, value: value.or(['string', '=>', (v) => v === 'on']) },
]
}

return prop
})
const mapTypes = <T extends typeof typee>(t: T) =>
t.map((prop) => {
const key = prop.key
const value = prop.value

if (value.extends(type.number)) {
return [prop, { key, value: value.or('string.numeric.parse') }]
}

if (value.extends('boolean')) {
return [
prop,
{ key, value: value.or(['string', '=>', (v) => v === 'on']) },
]
}

return prop
})
Is there a reason for this behavior? I would expect the key to already be present on the prop
27 replies
Aarktype
Created by PIat on 9/17/2024 in #questions
Dynamic type based on another value
Given a theoretical example like this:
const formDef = type({
agree: 'boolean',
clauses: ['===', 'first', 'second'],
})
const formDef = type({
agree: 'boolean',
clauses: ['===', 'first', 'second'],
})
Is it possible to only have clauses be required if agree is true?
24 replies
Aarktype
Created by PIat on 9/14/2024 in #questions
Extracting defaults at runtime
Hello! What is the canon way to extract the default values of the type on runtime? I'd like to uuse the defaults from the type as defaults in a form.
const formDef = type({
cars: '5 < number < 100 = 50',
name: ['string[]', '=', []],
active: 'boolean = true',
})

<Form
defaultValue={
// ...defaults from formDef
}
>
const formDef = type({
cars: '5 < number < 100 = 50',
name: ['string[]', '=', []],
active: 'boolean = true',
})

<Form
defaultValue={
// ...defaults from formDef
}
>
4 replies
Aarktype
Created by PIat on 9/14/2024 in #questions
Ark attest cannot find module error
Hello! In a pnpm monorepo, with @ark/attest installed in the workspace root and running pnpx run attest trace ., I get the following output:
...
Found & ignored ...
...
Starting: attest trace .
Debugger listening on ws://127.0.0.1:43611/c9521cad-1760-4b47-aa82-6525ed118c96
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module '/home/p/Documents/Projects/web/attest'
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
...
Found & ignored ...
...
Starting: attest trace .
Debugger listening on ws://127.0.0.1:43611/c9521cad-1760-4b47-aa82-6525ed118c96
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module '/home/p/Documents/Projects/web/attest'
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
What should I change to run it without issues?
156 replies
Aarktype
Created by PIat on 9/6/2024 in #questions
Extracting intent into runtime
Hello! What is the canon way to extract keys from types like these:
const type1 = type({
intent: '"hello"',
})

const type2 = type({
intent: '"hello"',
}).or({
intent: '"bye"',
})
const type1 = type({
intent: '"hello"',
})

const type2 = type({
intent: '"hello"',
}).or({
intent: '"bye"',
})
In a way that the resulting object is
{
intent: {
hello: 'hello'
}
}

{
intent: {
hello: 'hello',
bye: 'bye'
}
}
{
intent: {
hello: 'hello'
}
}

{
intent: {
hello: 'hello',
bye: 'bye'
}
}
? Would it be achieved with internal.distribute?
7 replies
Aarktype
Created by PIat on 9/4/2024 in #questions
Converting Zod to Arktype
Hello! I'm really interested in using Conform instead of React Hook Form for better DX and server-side capabilities. However, it doesn't have Ark support yet, so I'll have to create my own simple patch. Are there by any chance some examples or comparisons between Zod and Arktype architectures to go off of when translating these files, namely to extract the name of the constraints like Array in runtime? expression might be "key"? pun intended https://github.com/edmundhung/conform/blob/main/packages/conform-zod/constraint.ts https://github.com/edmundhung/conform/blob/main/packages/conform-zod/parse.ts Also, is there an way to do something like superRefine for custom run-time conditions? https://zod.dev/?id=superrefine
174 replies
Aarktype
Created by PIat on 8/30/2024 in #questions
Default number
Hello! Setting this brings the expected result, when ran through inferAmbient:
const queryType = type({
page: 'number',
})

// Result:
number
const queryType = type({
page: 'number',
})

// Result:
number
But adding a default value returns a function signature:
const queryType = type({
page: 'number = 1',
})

// Result
page?: ((In?: number | undefined) => Default<1>) | undefined
const queryType = type({
page: 'number = 1',
})

// Result
page?: ((In?: number | undefined) => Default<1>) | undefined
How can I get the number type in the editor when providing a default value?
133 replies
Aarktype
Created by PIat on 8/23/2024 in #questions
Accept number in string type
Hello! I'm parsing each value in a form with JSON.parse to convert string values like false to actual booleans. Unfortunately, this introduces the issue, that if someone inputs 123 into a text field, it gets parsed into a number type by JSON.parse. Then if the field is type string. An error is thrown, since number is not assignable to string. How should a type look like, if it should handle such a situation?
187 replies
Aarktype
Created by PIat on 8/22/2024 in #questions
Extract type from or
Hello! Is it possible, using the following schema:
const userType = type({
intent: "'profile'",
name: 'string>0',
surname: 'string>4',
})
.or({
intent: "'private'",
password: 'string>0',
})
const userType = type({
intent: "'profile'",
name: 'string>0',
surname: 'string>4',
})
.or({
intent: "'private'",
password: 'string>0',
})
to extract one of the types ("find" it by the intent field)? I'd like to use it for multiple forms on a page. It's possible to split it into multiple types, but having it in one type is more readable to me
25 replies
Aarktype
Created by PIat on 8/22/2024 in #questions
Get type without constraints
Hello! inferAmbient retuns types with constraints like moreThanLength<0>, which when I try to access values to, I get Type 'string' is not assignable to type 'moreThanLength<0>'. Is it possible to extract a more basic type?
15 replies
Aarktype
Created by PIat on 8/19/2024 in #questions
must be an instance of FormData (was object)
Hello! This code:
const formData = await request.clone().formData();

const formSchema = type({
name: 'string>0',
surname: 'string>0'
})

const parseForm = type('parse.formData').pipe(formSchema)

const formResult = parseForm(formData)
const formData = await request.clone().formData();

const formSchema = type({
name: 'string>0',
surname: 'string>0'
})

const parseForm = type('parse.formData').pipe(formSchema)

const formResult = parseForm(formData)
Throws following error:
must be an instance of FormData (was object)
must be an instance of FormData (was object)
However, formData is instanceof FormData and the log also says it's FormData:
ArkError {
input: {
code: 'proto',
description: 'an instance of FormData',
proto: [class FormData]
},
' arkKind': 'error',
path: [],
data: FormData { name: 'Plat', surname: '' },
...
ArkError {
input: {
code: 'proto',
description: 'an instance of FormData',
proto: [class FormData]
},
' arkKind': 'error',
path: [],
data: FormData { name: 'Plat', surname: '' },
...
What am I doing wrong?
38 replies
Aarktype
Created by PIat on 8/16/2024 in #questions
Error internationalization (i18n)
Hello! Is it possible to translate the errors into other languages? In my previous setup I was using this for such funtionality: https://github.com/aiji42/zod-i18n I saw this issue opened for individual fields, which would really be great: https://github.com/arktypeio/arktype/issues/722 Is this the way for "general" errors? https://github.com/arktypeio/arktype/issues/404
125 replies