Hm, been a while I did something with K/JS. Do we ...
# javascript
v
Hm, been a while I did something with K/JS. Do we have wrappers for Ajv?
t
Do you mean this Ajv?
v
Yes, exactly. Seems there are no wrappers. And Dukat is not yet revived, is it? What's the process to get new wrappers in? Afair there still was some generation involved?
t
What's the process to get new wrappers in?
We use Karakum in Kotlin Wrappers
I checked definitions, looks like Karakum can process them cc @Sergei Grishchenko
s
For now I am working on other activities for wrappers, but if you want to convert this lib using Karakum by yourself, I can help with consultation and advice.
πŸ˜€ 1
BTW, why not something more popular like Zod or Joi?
v
Just because it is the one that is used by https://schemastore.org/ to validate the schemas they host, so I thought it is a good choice
I assumed they know what they are doing and had a reason to choose that one πŸ™‚
Ah, wait, those are not JSON Schema validators
s
I see, I just didn't heard about this lib but I see, it is quite popular too (at least according to github stars πŸ˜„).
v
Then that's why
What I want to do is validating against a JSON schema
s
aaaa.... now I see
ok. make sense
v
Actually I want to validate input against a JSON schema, and in another place test the written JSON schema against valid and invalid inputs as QA measure :-)
πŸ‘Œ 1
but if you want to convert this lib using Karakum by yourself, I can help with consultation and advice.
You mean "to convert and have it in my project", or "to convert and bring it to kotlin-wrappers"?
s
It depends. I heard about different approaches. E.g. you can convert it roughly for you project, patch a bit by hands and use. But update to new version can be problematic with this strategy. On another hand, if you brave enough you can try to contribute to the wrappers, but in this case probably you will have to provide some converter plugins (written in JS) that provide stable conversion from version to version. Anyway I can help with both of these approches.
❀️ 1
v
Hm, is there also some documentation somwhere? I cannot even recognize or find out what is
types-kotlin
in relation to
kotlin-wrappers
, or what should go where under which conditions.
Maybe some contribution documentation would be helpful
t
types-kotlin
- legacy convertors
Example of Karakum usage - kotlin-typescript for example
v
Oh, so
types-kotlin
is not the way to go, right? I've seen that every readme, including
kotlin-typescript
(with the exception of
kotlin-node
) refers to
types-kotlin
, so started into looking at that.
t
We plan smooth (but very long) migration on Karakum
Generator near generated sources - is what we want
v
But not that slow, that new things get added to
types-kotlin
I guess πŸ˜„
t
No, we remove subprojects one by one
Node and TS declarations initially were generated by
types-kotlin
for example
Now they use Karakum
Ajv in Kotlin Wrappers - will be cool
It's missed part of JSO checking
In fact we can generate schemas from JSO-interface
v
Ah, no, I was wrong, I just searched for "Manual changes are prohibited" and that is only mentioned in the projects that mention
types-kotlin
and in
kotlin-node
just there with Karakum. So it is only wrong in
kotlin-typescript
and everywhere else only inconsistent ;-D
t
Usually we start start from empty subproject PR πŸ˜‰ Also bonus of Wrappers - ready infrastructure πŸ™‚
v
Hm, what does this want to tell me?
Copy code
file:///D:/Sourcecode/other/kotlin-wrappers/build/js/node_modules/karakum/build/generate.js:146
        plugin.setup(context);
               ^

TypeError: Cannot read properties of undefined (reading 'setup')
    at generate (file:///D:/Sourcecode/other/kotlin-wrappers/build/js/node_modules/karakum/build/generate.js:146:16)
    at async file:///D:/Sourcecode/other/kotlin-wrappers/build/js/node_modules/karakum/build/cli.js:23:1

Node.js v22.7.0
Is it an encrypted complaint that I copied over all plugins of another subproject and commented out all lines?
Not too obvious if it is πŸ˜„
Hm, and worse, I deleted the files but it still was there, because it took the files from
kotlin-wrappers/build/js/packages/kotlin-ajv
. Deleting the files in
kotlin-wrappers/kotlin-ajv
did not help, just deleting them there. Seems again somewhere someone used a
Copy
task where they should use a
Sync
task.
🧌 1
😬 1
Hm, I enabled
"libraryNameOutputPrefix": true
to get the file(s) within the package name directory and
"granularity": "top-level"
to get single files and not all-in-one. But now it wants generate an
ajv.kt
with most stuff and an
Ajv.kt
with an
external interface
for
Copy code
declare var ajv: {
  (options?: ajv.Options): ajv.Ajv;
  new(options?: ajv.Options): ajv.Ajv;
  ValidationError: typeof AjvErrors.ValidationError;
  MissingRefError: typeof AjvErrors.MissingRefError;
  $dataMetaSchema: object;
}
Do we even need the latter or is it safe to
ignoreOutput
it? πŸ˜•
If we need it, how to handle it?
Hm, I guess this should instead become the companion object of
ajv.Ajv
instead of a second
ajv.Ajv
interface. πŸ˜•
Hm, getting this into kotlin-wrappers might be above my current JS/TS skills. πŸ˜• Also, why are plugins not creatable in Kotlin/JS πŸ˜•
t
Also, why are plugins not creatable in Kotlin/JS πŸ˜•
It's planned next step πŸ˜‰
πŸ‘Œ 1
TS declarations were created for this particular case
v
which "this"?
For the case that I'm too dumb? πŸ˜„
t
For Karakum plugins
v
Oh, you mean TS declarations were created to support K/JS plugins, I see
But back to the topic, any idea how to resolve that situation properly? Actually, I don't even get it managed to run in a way I'm able to detach a debugger to the custom plugins.
t
сс @Sergei Grishchenko
v
At least I got it managed to attach a debugger, not that it helps me significantly with the situation as it is more a semantical problem than a technical first. πŸ˜„
πŸ‘ 1
Hm, I think I really need to give up here for now unless I get significantly more guidance. Even the builtin plugins generate non-compilable code in most basic ways. The
StringUnionTypePlugin.ts
for example produces
@seskar.js.JsValue("$id")
which then on compilation complains as it is a string template, not literal. πŸ˜•
But at least besides of the problem with Ajv.kt vs. ajv.kt, I at least got it down to only 9 compile errors. But I guess there are more semantical issues. πŸ˜•
t
The
StringUnionTypePlugin.ts
for example produces
@seskar.js.JsValue("$id")
which then on compilation complains as it is a string template, not literal. πŸ˜•
It's Karakum bug (new) 😞
πŸ‘Œ 2
s
I need some time to learn what is happening with this library, unfortunately I can't give you some promises, but I will try to investigate it on this weekend.
❀️ 1
v
Ok, after converting the other libs properly I used so far to gather some easier experience with something I'm familiar with a bit, back to this topic. So, did you have time to learn @Sergei Grishchenko? πŸ™‚ I guess not with the hackathon. Actually I just now recognized that there was an old version of Ajv in
package-lock.json
and that was converted and looked halfway manageable, while the actual current version looks much more problematic to me and might still be above my TS/JS knowledge. πŸ˜• For example there is a class
Ajv
in each,
core.d.ts
,
ajv.d.ts
, and
jtd.d.ts
. The latter two import the first one with a different name and extend it. When sending through Karakum it wants to put ll three into
Ajv.kt
and fails due to different modules. So how would I for example handle that?
s
It seems
core.d.ts
,
ajv.d.ts
, and
jtd.d.ts
are three different packages in terms of Java or Kotlin (see usages in screenshots). To be honest I didn't faced with such layout before. So it seems that we need to change package of output files not by file name, but by location in AST (if we are considering souse file as AST node). As simplest WA we can convert
core.d.ts
,
ajv.d.ts
, and
jtd.d.ts
as three independent packages, using 3 independent
karakum.config.json
, but I guess it is quite ugly solution πŸ™‚. I need to thin more about it and come out with some proposal.
Also I considered option to allow output mapping, something like that:
Copy code
"output": {
  "**/core.d.ts": "<project>/generated/core",
  "**/ajv.d.ts": "<project>/generated/ajv",
  "**/jtd.d.ts": "<project>/generated/jtd",
}
❀️ 1