Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/services/types/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { GenericParamMetadata, ParamClass, ParamType } from "./param";

// jq -r '[.result.objects | to_entries[] | .value.relationships // {} | keys[]] | unique | sort[]' ./response.json
Comment thread
veronnicka marked this conversation as resolved.
type RelationshipKey =
| "enrolledby"
| "ipaallowedtoperform_read_keys"
| "ipaallowedtoperform_write_delegation"
| "ipaallowedtoperform_write_keys"
| "ipalocation"
| "iparepltopomanagedsuffix"
| "managedby"
| "managing"
| "member"
| "memberhost"
| "memberindirect"
| "membermanager"
| "memberof"
| "memberofindirect"
| "memberuser"
| "role";

type Relationships = {
[K in RelationshipKey]: [string, null | string, string];
};

type AttributeMembers = {
[K in RelationshipKey]: RelationshipKey[];
};

type ObjectMetadata<T extends string> = {
name: T;
takes_params: GenericParamMetadata<ParamClass, ParamType>[];
methods: string[];
} & PrimaryKeyObjectMetadata;

type PrimaryKeyObjectMetadata = {
primary_key: string;
};

type ComplexObjectMetadata<T extends string> = {
parent_object: string;
container_dn: string;
object_name: string;
object_name_plural: string;
object_class: string[];
object_class_config: null;
default_attributes: string[];
label: string;
label_singular: string;
hidden_attributes: string[];
uuid_attribute: string;
attribute_member: AttributeMembers;
rdn_attribute: string;
bindable: boolean;
relationships: Relationships;
primary_key: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you are already adding the PrimaryKeyObjectMetadata, so why have the primary_key here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an oversight, thank you.

aciattrs: string[];
can_have_permissions: boolean;
} & PrimaryKeyObjectMetadata &
ObjectMetadata<T>;

type ObjectRecord<T extends string> = {
[K in T]: ObjectMetadata<T> | ComplexObjectMetadata<T>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not using the K here. Did you mean ObjectMetadata<K> ?

};

type MethodRecord<T extends string> = {
doc: string;
NO_CLI: boolean;
takes_options: GenericParamMetadata<ParamClass, ParamType>[];
} & ObjectMetadata<T>;

export type Metadata = {
objects: ObjectRecord<string>;
methods: MethodRecord<string>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only be one method though, right? why the plural form then?

Also, why are methods and commands with the same type. what is the reason for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A mistake, it should be an array. I don't know why the types are equal, commands contain every function, while methods are bounds to objects, say user, user_find, user_add... commands also contains utilities such as batch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think after a certain point I just gave up, as mapping this type is too complex and useless.

commands: MethodRecord<string>;
};
Loading