Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some findings #1

Open
sebilasse opened this issue Feb 16, 2022 · 3 comments
Open

some findings #1

sebilasse opened this issue Feb 16, 2022 · 3 comments

Comments

@sebilasse
Copy link

sebilasse commented Feb 16, 2022

Hello,

thanks for the nice ActivityPub meeting.

There are some initial findings and I made a CodeSandbox to play with it. Forgive me, I know it is a WIP …

In the README.md it is missing the import "reflect-metadata"; line.
Also it seems to act async and have the array of errors in the promise resolution (?)

validate(note).then(update);
  • As you can see in the codesandbox, it somehow assumes that the name property is required but I think it is not.
  1. Should pass (name is not required) but does not
{
  type: "Object",
  id: "https://yuforium.com/users/chris/note-123"
}

  • It is superimportant that the type property can be an Array.
  • Many things can be Arrays in ActivityStreams …
  1. Should pass (type can be an Array) but does not
{
  type: ["Article", "schema:NewsArticle"],
  id: "https://yuforium.com/users/chris/note-123",
  name: "with name",
}

  • properties which are marked as functional can't be an Array.

Bildschirmfoto 2022-02-16 um 13 55 57

  1. Should NOT pass (latitude must be functional) but does pass
{
  type: "Object",
  id: "https://yuforium.com/users/chris/note-123",
  name: "with name",
  latitude: [4.4]
}
@cpmoser
Copy link
Contributor

cpmoser commented Feb 20, 2022

thanks @sebilasse ! I really enjoyed participating in the meeting and look forward to the next one. Really appreciate the comment and I will add fixes for all of the items you mentioned. Those will go out in 0.0.5 which I hope to release in the next couple of days.

One of the things that is not mentioned in the README is using class-transformer to transform properties in a Activity Streams json format to an equivalent JS object, which I will document this in the next release. Having multiple types introduces an interesting possibility which would be to use Typescript mixins to provide behaviors to the classes that are created (something I was considering anyway) - so we could take advantage of composability here. Anyway, I'll put in support for multiple types in the next release, and then look at switching from inheritance to composition after that.

@sebilasse
Copy link
Author

sebilasse commented Apr 6, 2023

So, I looked into it. The transformer is mentioned now. The problem:
This works just on the TS/JS/JSON level but it will not extend the JSON-LD @context
which would make other ActivityPub implementations aware …

I think, we can do better with some custom decorators.
In general, in redaktor any
@context
Actor, Activity, Object independent from @context
• media independent from Objects
gets its own URL and cid (same as in ipfs)
Then we can have a cache of contexts while decorating (cid) and even users could extend a system from anywhere (if allowed) and get an URL for the context.

I have put the decorators in a gist but it is in deno, sorry (this would be the @jsonld import)
https://gist.github.com/sebilasse/98aa5e5fa6718e5443cbe0d02e2e27eb

Trying to give a short demo …
Put this e.g. in test.ts and run it
deno run --allow-net --allow-env --allow-read --allow-write --allow-sys test.ts

import { Reflect } from "https://deno.land/x/reflect_metadata@v0.1.12/mod.ts";
import { context, id, type, container, protect } from "@jsonld";

@context("as")
class AS {
  constructor(args: AS) {}
  @id("as:name") @container.set @type.string @protect
  protected name: string | string[];
  xy: any
}

@context("redaktor")
class MyClass extends AS {
  constructor(args: MyClass) { super(args) }
  @id("wdt:P2048") @type.integerPositive
  population: number;
  @id("redaktor:test") @type.idOrObject @protect
  protected anotherProperty: string;
  // SHOULD error cause protected:
  /* 
  @id("as:name") @container.set @type.string
  name: string | string[];
  */
}


const x = new MyClass({population: 2, name: "Ed", xy:() => { return ""}});

const JSONRES = JSON.stringify(x, null, 2); // <- THE MAGIC
console.log(x, '___', JSONRES, '___');

The above are shortcuts, you can also use it like e.g. @type("dc:kryptonite"),
The runtime validation I do is its own portable JSON, a https://json-schema.org
See "we can then restrict runtime validation further …" in the gist.
And if you would use unknown prefixes, define em in @context like @context("dc", {dc: "http://urlForUnknownPrefix"})

Let's have a next meeting.

@sebilasse
Copy link
Author

note to me, it is missing some Object.assign to make runtime validation runtime typesafe
https://stackoverflow.com/a/41853194/1008547

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants