Added a CreateResourceOption

main
Jackson Morgan 5 months ago
parent b6755128db
commit de7923c2ca
  1. 23
      packages/connected-nextgraph/src/NextGraphConnectedPlugin.ts
  2. 3
      packages/connected-solid/src/SolidConnectedPlugin.ts
  3. 10
      packages/connected/src/ConnectedLdoDataset.ts
  4. 3
      packages/connected/src/ConnectedPlugin.ts
  5. 1
      packages/connected/src/IConnectedLdoDataset.ts

@ -7,12 +7,19 @@ import { isNextGraphUri } from "./util/isNextGraphUri";
export interface NextGraphConnectedContext {
sessionId?: string;
}
export interface NextGraphCreateResourceOptions {
storeType?: "public" | "protected" | "private";
storeRepo?: string;
}
export interface NextGraphConnectedPlugin
extends ConnectedPlugin<
"nextgraph",
NextGraphUri,
NextGraphResource,
NextGraphConnectedContext
NextGraphConnectedContext,
NextGraphCreateResourceOptions
> {
name: "nextgraph";
getResource: (
@ -35,18 +42,18 @@ export const nextgGraphConnectedPlugin: NextGraphConnectedPlugin = {
createResource: async function (
context: ConnectedContext<NextGraphConnectedPlugin[]>,
options?: NextGraphCreateResourceOptions,
): Promise<NextGraphResource> {
const storeType = options?.storeType ?? "protected";
// TODO: determine the name of the store repo from the session id.
const storeRepo = options?.storeRepo ?? "";
const nuri: NextGraphUri = await ng.doc_create(
context.nextgraph.sessionId,
"Graph",
// NIKO: Can this always be "data:graph"?
"data:graph",
// NIKO: What are the options here again? "private" "protected" "public"
"protected",
// NIKO: What is this? Should it be changed? lookup what the default store
// is
"B381BvfdAFYPBkdhDrsqnMMg5pnJMWJgJbZobZErXZMA",
// NIKO: Can this always be "store"? yes
storeType,
storeRepo,
"store",
);
return new NextGraphResource(nuri, context);

@ -12,7 +12,8 @@ export interface SolidConnectedPlugin
"solid",
SolidUri,
SolidLeaf | SolidContainer,
SolidConnectedContext
SolidConnectedContext,
undefined
> {
name: "solid";
getResource:

@ -146,11 +146,17 @@ export class ConnectedLdoDataset<
async createResource<
Name extends Plugins[number]["name"],
Plugin extends Extract<Plugins[number], { name: Name }>,
>(name: Name): Promise<ReturnType<Plugin["createResource"]>> {
>(
name: Name,
createResourceOptions?: Plugin["types"]["createResourceOptions"],
): Promise<ReturnType<Plugin["createResource"]>> {
const validPlugin = this.plugins.find((plugin) => name === plugin.name)!;
const newResourceResult = await validPlugin.createResource(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore I have no idea why this doesn't work
const newResourceResult = await validPlugin.createResource(this.context);
this.context,
createResourceOptions,
);
// HACK: cast to any
if (newResourceResult.isError) return newResourceResult as any;
this.resourceMap.set(newResourceResult.uri, newResourceResult);

@ -8,11 +8,13 @@ export interface ConnectedPlugin<
UriType extends string = any,
ResourceType extends Resource<UriType> = any,
ContextType = any,
CreateResourceOptions = any,
> {
name: Name;
getResource(uri: UriType, context: ConnectedContext<this[]>): ResourceType;
createResource(
context: ConnectedContext<this[]>,
createResourceOptions?: CreateResourceOptions,
): Promise<ResourceType | ErrorResult>;
isUriValid(uri: string): uri is UriType;
normalizeUri?: (uri: UriType) => UriType;
@ -23,5 +25,6 @@ export interface ConnectedPlugin<
uri: UriType;
context: ContextType;
resource: ResourceType;
createResourceOptions: CreateResourceOptions;
};
}

@ -50,6 +50,7 @@ export interface IConnectedLdoDataset<Plugins extends ConnectedPlugin[]>
Plugin extends Extract<Plugins[number], { name: Name }>,
>(
name: Name,
createResourceOptions?: Plugin["types"]["createResourceOptions"],
): Promise<ReturnType<Plugin["createResource"]>>;
forgetResource(uri: string): boolean;

Loading…
Cancel
Save