@learncard/core 9.0.2 → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  import { LearnCard, Plugin } from './wallet';
2
- export type GetPlugins<LC extends LearnCard<any, any, any>> = LC['plugins'];
3
- export type AddPlugin<LC extends LearnCard<any, any, any>, P extends Plugin> = LearnCard<[
2
+ export declare type GetPlugins<LC extends LearnCard<any, any, any>> = LC['plugins'];
3
+ export declare type AddPlugin<LC extends LearnCard<any, any, any>, P extends Plugin> = LearnCard<[
4
4
  ...GetPlugins<LC>,
5
5
  P
6
6
  ]>;
@@ -1,3 +1,3 @@
1
- export type OmitNevers<T extends Record<string, any>> = Omit<T, {
1
+ export declare type OmitNevers<T extends Record<string, any>> = Omit<T, {
2
2
  [Index in keyof T]: [T[Index]] extends [never] ? Index : never;
3
3
  }[keyof T]>;
@@ -3,22 +3,22 @@ import { Query } from 'sift';
3
3
  import { Plugin } from './wallet';
4
4
  import { OmitNevers } from './helpers';
5
5
  import { DeepPartial } from './utilities';
6
- export type CacheStrategy = 'cache-only' | 'cache-first' | 'skip-cache';
7
- export type PlaneOptions = {
6
+ export declare type CacheStrategy = 'cache-only' | 'cache-first' | 'skip-cache';
7
+ export declare type PlaneOptions = {
8
8
  cache?: CacheStrategy;
9
9
  };
10
- export type ControlPlane = 'read' | 'store' | 'index' | 'cache' | 'id';
11
- export type FilterForPlane<Plugins extends Plugin[], Plane extends ControlPlane> = [
10
+ export declare type ControlPlane = 'read' | 'store' | 'index' | 'cache' | 'id' | 'context';
11
+ export declare type FilterForPlane<Plugins extends Plugin[], Plane extends ControlPlane> = [
12
12
  Plugins
13
13
  ] extends [1 & Plugins] ? any : {
14
14
  [Index in keyof Plugins]: undefined extends Plugins[Index][Plane] ? never : Plugins[Index]['name'];
15
15
  }[number];
16
- export type GetPlanesForPlugins<Plugins extends Plugin[]> = any[] extends Plugins ? never : {
16
+ export declare type GetPlanesForPlugins<Plugins extends Plugin[]> = any[] extends Plugins ? never : {
17
17
  [Index in keyof Plugins]: {
18
18
  [Key in ControlPlane]: undefined extends Plugins[Index][Key] ? never : Key;
19
19
  }[ControlPlane];
20
20
  }[number];
21
- export type GetPlaneProviders<Plugins extends Plugin[], Plane extends ControlPlane> = any[] extends Plugins ? any : {
21
+ export declare type GetPlaneProviders<Plugins extends Plugin[], Plane extends ControlPlane> = any[] extends Plugins ? any : {
22
22
  [Index in keyof Plugins]: undefined extends Plugins[Index][Plane] ? never : OmitNevers<{
23
23
  [Name in Plugins[number]['name']]: Name extends Plugins[Index]['name'] ? {
24
24
  name: Name;
@@ -27,26 +27,26 @@ export type GetPlaneProviders<Plugins extends Plugin[], Plane extends ControlPla
27
27
  } : never;
28
28
  }>;
29
29
  }[number];
30
- export type ReadPlane = {
30
+ export declare type ReadPlane = {
31
31
  get: (uri?: string, options?: PlaneOptions) => Promise<VC | VP | undefined>;
32
32
  };
33
- export type PluginReadPlane = ReadPlane;
34
- export type LearnCardReadPlane<Plugins extends Plugin[]> = ReadPlane & {
33
+ export declare type PluginReadPlane = ReadPlane;
34
+ export declare type LearnCardReadPlane<Plugins extends Plugin[]> = ReadPlane & {
35
35
  providers: GetPlaneProviders<Plugins, 'read'>;
36
36
  };
37
- export type EncryptionParams = {
37
+ export declare type EncryptionParams = {
38
38
  recipients: string[];
39
39
  };
40
- export type StorePlane = {
40
+ export declare type StorePlane = {
41
41
  upload: (vc: VC | VP, options?: PlaneOptions) => Promise<string>;
42
42
  uploadMany?: (vcs: (VC | VP)[], options?: PlaneOptions) => Promise<string[]>;
43
43
  uploadEncrypted?: (vc: VC | VP, params?: EncryptionParams, options?: PlaneOptions) => Promise<string>;
44
44
  };
45
- export type PluginStorePlane = StorePlane;
46
- export type LearnCardStorePlane<Plugins extends Plugin[]> = Record<FilterForPlane<Plugins, 'store'>, StorePlane> & {
45
+ export declare type PluginStorePlane = StorePlane;
46
+ export declare type LearnCardStorePlane<Plugins extends Plugin[]> = Record<FilterForPlane<Plugins, 'store'>, StorePlane> & {
47
47
  providers: GetPlaneProviders<Plugins, 'store'>;
48
48
  };
49
- export type IndexPlane = {
49
+ export declare type IndexPlane = {
50
50
  get: <Metadata extends Record<string, any> = Record<never, never>>(query?: Partial<Query<CredentialRecord<Metadata>>>, options?: PlaneOptions) => Promise<CredentialRecord<Metadata>[]>;
51
51
  getPage?: <Metadata extends Record<string, any> = Record<never, never>>(query?: Partial<Query<CredentialRecord<Metadata>>>, paginationOptions?: {
52
52
  limit?: number;
@@ -63,12 +63,12 @@ export type IndexPlane = {
63
63
  remove: (id: string, options?: PlaneOptions) => Promise<boolean>;
64
64
  removeAll?: (options?: PlaneOptions) => Promise<boolean>;
65
65
  };
66
- export type PluginIndexPlane = IndexPlane;
67
- export type LearnCardIndexPlane<Plugins extends Plugin[]> = {
66
+ export declare type PluginIndexPlane = IndexPlane;
67
+ export declare type LearnCardIndexPlane<Plugins extends Plugin[]> = {
68
68
  all: Pick<IndexPlane, 'get'>;
69
69
  providers: GetPlaneProviders<Plugins, 'index'>;
70
70
  } & Record<FilterForPlane<Plugins, 'index'>, IndexPlane>;
71
- export type CachePlane = {
71
+ export declare type CachePlane = {
72
72
  getIndex: <Metadata extends Record<string, any> = Record<never, never>>(name: string, query: Partial<Query<CredentialRecord<Metadata>>>) => Promise<CredentialRecord<Metadata>[] | undefined>;
73
73
  setIndex: <Metadata extends Record<string, any> = Record<never, never>>(name: string, query: Partial<Query<CredentialRecord<Metadata>>>, value: CredentialRecord<Metadata>[]) => Promise<boolean>;
74
74
  getIndexPage: <Metadata extends Record<string, any> = Record<never, never>>(name: string, query: Partial<Query<CredentialRecord<Metadata>>>, paginationOptions?: {
@@ -94,15 +94,25 @@ export type CachePlane = {
94
94
  setVc: (uri: string, value: VC | VP | undefined) => Promise<boolean>;
95
95
  flushVc: () => Promise<boolean>;
96
96
  };
97
- export type PluginCachePlane = CachePlane;
98
- export type LearnCardCachePlane<Plugins extends Plugin[]> = CachePlane & {
97
+ export declare type PluginCachePlane = CachePlane;
98
+ export declare type LearnCardCachePlane<Plugins extends Plugin[]> = CachePlane & {
99
99
  providers: GetPlaneProviders<Plugins, 'cache'>;
100
100
  };
101
- export type IdPlane = {
101
+ export declare type IdPlane = {
102
102
  did: (method?: string, options?: PlaneOptions) => string;
103
103
  keypair: (algorithm?: string, options?: PlaneOptions) => JWK;
104
104
  };
105
- export type PluginIdPlane = IdPlane;
106
- export type LearnCardIdPlane<Plugins extends Plugin[]> = IdPlane & {
105
+ export declare type PluginIdPlane = IdPlane;
106
+ export declare type LearnCardIdPlane<Plugins extends Plugin[]> = IdPlane & {
107
107
  providers: GetPlaneProviders<Plugins, 'id'>;
108
108
  };
109
+ export declare type ContextPlane = {
110
+ resolveDocument: (uri: string, allowRemote?: boolean) => Promise<Record<string, any> | undefined>;
111
+ };
112
+ export declare type PluginContextPlane = {
113
+ resolveStaticDocument: (uri: string) => Promise<Record<string, any> | undefined>;
114
+ resolveRemoteDocument?: (uri: string) => Promise<Record<string, any> | undefined>;
115
+ };
116
+ export declare type LearnCardContextPlane<Plugins extends Plugin[]> = ContextPlane & {
117
+ providers: GetPlaneProviders<Plugins, 'context'>;
118
+ };
@@ -1,18 +1,18 @@
1
1
  /** @group Utility Types */
2
- export type Tail<T extends any[]> = T extends [any, ...infer R] ? R : never;
2
+ export declare type Tail<T extends any[]> = T extends [any, ...infer R] ? R : never;
3
3
  /** @group Utility Types */
4
- export type Last<T extends any[]> = T extends [...any[], infer R] ? R : never;
4
+ export declare type Last<T extends any[]> = T extends [...any[], infer R] ? R : never;
5
5
  /** @group Utility Types */
6
- export type RemoveLast<T extends any[]> = T extends [...infer R, any] ? R : [];
6
+ export declare type RemoveLast<T extends any[]> = T extends [...infer R, any] ? R : [];
7
7
  /** @group Utility Types */
8
- export type RemoveFirstArg<T extends (...args: any[]) => any> = (args: Tail<Parameters<T>>) => ReturnType<T>;
8
+ export declare type RemoveFirstArg<T extends (...args: any[]) => any> = (args: Tail<Parameters<T>>) => ReturnType<T>;
9
9
  /** @group Utility Types */
10
- export type RemoveLastArg<T extends (...args: any[]) => any> = (args: RemoveLast<Parameters<T>>) => ReturnType<T>;
10
+ export declare type RemoveLastArg<T extends (...args: any[]) => any> = (args: RemoveLast<Parameters<T>>) => ReturnType<T>;
11
11
  /** @group Utility Types */
12
- export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
12
+ export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
13
13
  /** @group Utility Types */
14
- export type MergeObjects<Objects extends Record<string, any>[]> = undefined extends Objects[2] ? Omit<Objects[0], keyof Objects[1]> & Objects[1] : Omit<MergeObjects<RemoveLast<Objects>>, keyof Last<Objects>> & Last<Objects>;
14
+ export declare type MergeObjects<Objects extends Record<string, any>[]> = undefined extends Objects[2] ? Omit<Objects[0], keyof Objects[1]> & Objects[1] : Omit<MergeObjects<RemoveLast<Objects>>, keyof Last<Objects>> & Last<Objects>;
15
15
  /** @group Utility Types */
16
- export type DeepPartial<T> = T extends object ? {
16
+ export declare type DeepPartial<T> = T extends object ? {
17
17
  [P in keyof T]?: DeepPartial<T[P]>;
18
18
  } : T;
@@ -1,17 +1,17 @@
1
- import { ControlPlane, GetPlanesForPlugins, PluginReadPlane, PluginStorePlane, PluginIndexPlane, PluginCachePlane, PluginIdPlane, LearnCardReadPlane, LearnCardStorePlane, LearnCardIndexPlane, LearnCardCachePlane, LearnCardIdPlane } from './planes';
1
+ import { ControlPlane, GetPlanesForPlugins, PluginReadPlane, PluginStorePlane, PluginIndexPlane, PluginCachePlane, PluginIdPlane, PluginContextPlane, LearnCardReadPlane, LearnCardStorePlane, LearnCardIndexPlane, LearnCardCachePlane, LearnCardIdPlane, LearnCardContextPlane } from './planes';
2
2
  import { UnionToIntersection, MergeObjects } from './utilities';
3
- export type GenerateLearnCard<NewControlPlanes extends ControlPlane = never, NewMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, ControlPlanes extends ControlPlane = never, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>> = LearnCard<any, [
3
+ export declare type GenerateLearnCard<NewControlPlanes extends ControlPlane = never, NewMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, ControlPlanes extends ControlPlane = never, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>> = LearnCard<any, [
4
4
  ControlPlanes
5
5
  ] extends [1 & ControlPlanes] ? NewControlPlanes : [NewControlPlanes] extends [1 & NewControlPlanes] ? ControlPlanes : ControlPlanes | NewControlPlanes, NewMethods & Methods>;
6
- export type AddImplicitLearnCardArgument<Functions extends Record<string, (...args: any[]) => any> = Record<never, never>, ControlPlanes extends ControlPlane = never, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>, DependentControlPlanes extends ControlPlane = never, DependentMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
6
+ export declare type AddImplicitLearnCardArgument<Functions extends Record<string, (...args: any[]) => any> = Record<never, never>, ControlPlanes extends ControlPlane = never, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>, DependentControlPlanes extends ControlPlane = never, DependentMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
7
7
  [Key in keyof Functions]: <T extends GenerateLearnCard<ControlPlanes, Methods, DependentControlPlanes, DependentMethods>>(learnCard: T, ...args: Parameters<Functions[Key]>) => ReturnType<Functions[Key]>;
8
8
  };
9
9
  /** @group Universal Wallets */
10
- export type GetPluginMethods<Plugins extends Plugin[]> = undefined extends Plugins[1] ? NonNullable<Plugins[0]['_methods']> : UnionToIntersection<NonNullable<MergeObjects<{
10
+ export declare type GetPluginMethods<Plugins extends Plugin[]> = undefined extends Plugins[1] ? NonNullable<Plugins[0]['_methods']> : UnionToIntersection<NonNullable<MergeObjects<{
11
11
  [Key in keyof Plugins]: NonNullable<Plugins[Key]['_methods']>;
12
12
  }>>>;
13
13
  /** @group Universal Wallets */
14
- export type Plugin<Name extends string = string, ControlPlanes extends ControlPlane = any, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>, DependentControlPlanes extends ControlPlane = never, DependentMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
14
+ export declare type Plugin<Name extends string = string, ControlPlanes extends ControlPlane = any, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>, DependentControlPlanes extends ControlPlane = never, DependentMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
15
15
  name: Name;
16
16
  displayName?: string;
17
17
  description?: string;
@@ -22,6 +22,7 @@ export type Plugin<Name extends string = string, ControlPlanes extends ControlPl
22
22
  index?: {};
23
23
  cache?: {};
24
24
  id?: {};
25
+ context?: {};
25
26
  } & ([ControlPlanes] extends [1 & ControlPlanes] ? {} : ('read' extends ControlPlanes ? {
26
27
  read: AddImplicitLearnCardArgument<PluginReadPlane, ControlPlanes, Methods, DependentControlPlanes, DependentMethods>;
27
28
  } : {}) & ('store' extends ControlPlanes ? {
@@ -32,9 +33,11 @@ export type Plugin<Name extends string = string, ControlPlanes extends ControlPl
32
33
  cache: AddImplicitLearnCardArgument<PluginCachePlane, ControlPlanes, Methods, DependentControlPlanes, DependentMethods>;
33
34
  } : {}) & ('id' extends ControlPlanes ? {
34
35
  id: AddImplicitLearnCardArgument<PluginIdPlane, ControlPlanes, Methods, DependentControlPlanes, DependentMethods>;
36
+ } : {}) & ('context' extends ControlPlanes ? {
37
+ context: AddImplicitLearnCardArgument<PluginContextPlane, ControlPlanes, Methods, DependentControlPlanes, DependentMethods>;
35
38
  } : {}));
36
39
  /** @group Universal Wallets */
37
- export type LearnCard<Plugins extends Plugin[] = [], ControlPlanes extends ControlPlane = GetPlanesForPlugins<Plugins>, PluginMethods = GetPluginMethods<Plugins>> = {
40
+ export declare type LearnCard<Plugins extends Plugin[] = [], ControlPlanes extends ControlPlane = GetPlanesForPlugins<Plugins>, PluginMethods = GetPluginMethods<Plugins>> = {
38
41
  plugins: Plugins;
39
42
  invoke: PluginMethods;
40
43
  addPlugin: <NewPlugin extends Plugin>(plugin: NewPlugin) => Promise<LearnCard<[...Plugins, NewPlugin]>>;
@@ -49,4 +52,6 @@ export type LearnCard<Plugins extends Plugin[] = [], ControlPlanes extends Contr
49
52
  cache: LearnCardCachePlane<Plugins>;
50
53
  } : {}) & ('id' extends ControlPlanes ? {
51
54
  id: LearnCardIdPlane<Plugins>;
55
+ } : {}) & ('context' extends ControlPlanes ? {
56
+ context: LearnCardContextPlane<Plugins>;
52
57
  } : {}));
@@ -12,4 +12,5 @@ export declare const generateLearnCard: <Plugins extends {
12
12
  index?: {} | undefined;
13
13
  cache?: {} | undefined;
14
14
  id?: {} | undefined;
15
+ context?: {} | undefined;
15
16
  }[] = [], ControlPlanes extends GetPlanesForPlugins<Plugins> = GetPlanesForPlugins<Plugins>, PluginMethods extends GetPluginMethods<Plugins> = GetPluginMethods<Plugins>>(_learnCard?: Partial<LearnCard<Plugins, ControlPlanes, PluginMethods>>) => Promise<LearnCard<Plugins, ControlPlanes, PluginMethods>>;
@@ -1,2 +1,2 @@
1
1
  import { Plugin } from '../../../types/wallet';
2
- export type TestCachePlugin = Plugin<'Test Cache', 'cache'>;
2
+ export declare type TestCachePlugin = Plugin<'Test Cache', 'cache'>;
@@ -1,2 +1,2 @@
1
1
  import { Plugin } from '../../../types/wallet';
2
- export type TestIndexPlugin = Plugin<'Test Index', 'index'>;
2
+ export declare type TestIndexPlugin = Plugin<'Test Index', 'index'>;
@@ -1,2 +1,2 @@
1
1
  import { Plugin } from '../../../types/wallet';
2
- export type TestStoragePlugin = Plugin<'Test Storage', 'read' | 'store' | 'index'>;
2
+ export declare type TestStoragePlugin = Plugin<'Test Storage', 'read' | 'store' | 'index'>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@learncard/core",
3
- "version": "9.0.2",
3
+ "version": "9.1.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/core.esm.js",
@@ -40,7 +40,7 @@
40
40
  "isomorphic-fetch": "^3.0.0",
41
41
  "isomorphic-webcrypto": "^2.3.8",
42
42
  "zod": "^3.20.2",
43
- "@learncard/helpers": "1.0.6"
43
+ "@learncard/helpers": "1.0.7"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.js && tsc --p tsconfig.build.json && tsc-alias",