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

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

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

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

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

Loading…
Cancel
Save