Skip to content

Commit

Permalink
chore(schema): add a ts definition
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Aug 22, 2023
1 parent 2baf44b commit 92ca4a6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/schema/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./lavamoat-policy.v0-0-1.schema";
72 changes: 72 additions & 0 deletions packages/core/schema/lavamoat-policy.v0-0-1.schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Adapted from `type-fest` and simplified
*/
export type RequireAtLeastOne<
ObjectType,
KeysType extends keyof ObjectType = keyof ObjectType
> = {
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> &
Partial<Pick<ObjectType, Exclude<KeysType, Key>>>;
}[KeysType];

/**
* Schema for LavaMoat policy files
*/
export type LavaMoatPolicySchema = RequireAtLeastOne<
PartialLavaMoatPolicySchema,
"resources" | "resolutions"
>;

export interface PartialLavaMoatPolicySchema {
resources?: Resources;
resolutions?: Resolutions;
}

/**
* Describe the resources available to your application and direct dependencies
*/
export interface Resources {
[k: "<root>" | string]: ResourcePolicy;
}

export interface ResourcePolicy {
globals?: Globals;
builtins?: NodeJsBuiltins;
packages?: ExternalPackages;
}

/**
* Globals (including properties using dot notation) accessible to the module; `true` to allow and `false` to deny
*/
export interface Globals {
[k: string]: boolean;
}

/**
* Node.js builtins (including properties using dot notation); `true` to allow and `false` to deny
*/
export interface NodeJsBuiltins {
[k: string]: boolean;
}

/**
* Additional external packages (in their entirety) accessible to the module; `true` to allow and `false` to deny
*/
export interface ExternalPackages {
[k: string]: boolean;
}

/**
* Custom run-time module resolutions by direct dependency
*/
export interface Resolutions {
/**
* The key is the dependency name
*/
[k: string]: {
/**
* The key is the original module path and the value is the new module path
*/
[k: string]: string;
};
}

0 comments on commit 92ca4a6

Please sign in to comment.