iso-ucan 0.0.1 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/server.d.ts +41 -4
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/server.js +47 -0
- package/src/server.ts +0 -24
package/dist/src/server.d.ts
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @import { RouteOutput, StandardSchemaV1, RouteOptions, RouteHandlerOptions} from './types'
|
|
3
|
+
* @import {Capability} from './capability'
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Workaround to make imports types work
|
|
7
|
+
* @template {Capability<StandardSchemaV1, string>} T
|
|
8
|
+
* @template Output
|
|
9
|
+
* @typedef {Object} DELETE_ME
|
|
10
|
+
* @prop {string} url
|
|
11
|
+
* @prop {Capability<StandardSchemaV1, string>[]} capabilities
|
|
12
|
+
* @prop {RouteOutput<T, Output>} router
|
|
13
|
+
* @prop {RouteOptions<T, Output>} options
|
|
14
|
+
* @prop {RouteHandlerOptions} routerClient
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @template Output
|
|
18
|
+
* @template {Capability<StandardSchemaV1>} Cap
|
|
19
|
+
* @param {RouteOptions<Cap, Output>} options
|
|
20
|
+
* @returns {RouteOutput<Cap, Output>}
|
|
21
|
+
*/
|
|
22
|
+
export function route<Output, Cap extends Capability<StandardSchemaV1>>(options: RouteOptions<Cap, Output>): RouteOutput<Cap, Output>;
|
|
23
|
+
/**
|
|
24
|
+
* Workaround to make imports types work
|
|
25
|
+
*/
|
|
26
|
+
export type DELETE_ME<T extends Capability<StandardSchemaV1, string>, Output> = {
|
|
27
|
+
url: string;
|
|
28
|
+
capabilities: Capability<StandardSchemaV1, string>[];
|
|
29
|
+
router: RouteOutput<T, Output>;
|
|
30
|
+
options: RouteOptions<T, Output>;
|
|
31
|
+
routerClient: RouteHandlerOptions;
|
|
32
|
+
};
|
|
33
|
+
import type { StandardSchemaV1 } from './types';
|
|
34
|
+
import type { Capability } from './capability';
|
|
35
|
+
import type { RouteOptions } from './types';
|
|
36
|
+
import type { RouteOutput } from './types';
|
|
37
|
+
import type { StandardSchemaV1 as StandardSchemaV1_1 } from './types';
|
|
38
|
+
import type { Capability as Capability_1 } from './capability';
|
|
39
|
+
import type { RouteOutput as RouteOutput_1 } from './types';
|
|
40
|
+
import type { RouteOptions as RouteOptions_1 } from './types';
|
|
41
|
+
import type { RouteHandlerOptions } from './types';
|
|
5
42
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/src/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;GAKG;AACH,sBALa,MAAM,EACyB,GAAG,SAAlC,WAAY,gBAAgB,CAAE,WAChC,aAAa,GAAG,EAAE,MAAM,CAAC,GACvB,YAAY,GAAG,EAAE,MAAM,CAAC,CAqBpC;;;;sBAnCmD,CAAC,SAAxC,WAAY,gBAAgB,EAAE,MAAM,CAAE,EACtC,MAAM;SAET,MAAM;kBACN,WAAW,gBAAgB,EAAE,MAAM,CAAC,EAAE;YACtC,YAAY,CAAC,EAAE,MAAM,CAAC;aACtB,aAAa,CAAC,EAAE,MAAM,CAAC;kBACvB,mBAAmB;;sCAbuD,SAAS;gCAChE,cAAc;kCADyC,SAAS;iCAAT,SAAS;4DAAT,SAAS;gDAChE,cAAc;kDADyC,SAAS;oDAAT,SAAS;yCAAT,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iso-ucan",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"description": "Isomorphic UCAN",
|
|
6
6
|
"author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -110,9 +110,9 @@
|
|
|
110
110
|
"iso-web": "^1.1.1",
|
|
111
111
|
"it-merge": "^3.0.12",
|
|
112
112
|
"multiformats": "^13.3.7",
|
|
113
|
-
"iso-base": "^4.0
|
|
114
|
-
"iso-did": "^
|
|
115
|
-
"iso-signatures": "^0.
|
|
113
|
+
"iso-base": "^4.1.0",
|
|
114
|
+
"iso-did": "^2.0.0",
|
|
115
|
+
"iso-signatures": "^0.4.0"
|
|
116
116
|
},
|
|
117
117
|
"devDependencies": {
|
|
118
118
|
"@types/node": "^24.1.0",
|
package/src/server.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
2
|
+
// import type { Capability } from './capability.js'
|
|
3
|
+
// import type { RouteHandlerOptions, RouteOptions, RouteOutput } from './types.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @import { RouteOutput, StandardSchemaV1, RouteOptions, RouteHandlerOptions} from './types'
|
|
7
|
+
* @import {Capability} from './capability'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Workaround to make imports types work
|
|
12
|
+
* @template {Capability<StandardSchemaV1, string>} T
|
|
13
|
+
* @template Output
|
|
14
|
+
* @typedef {Object} DELETE_ME
|
|
15
|
+
* @prop {string} url
|
|
16
|
+
* @prop {Capability<StandardSchemaV1, string>[]} capabilities
|
|
17
|
+
* @prop {RouteOutput<T, Output>} router
|
|
18
|
+
* @prop {RouteOptions<T, Output>} options
|
|
19
|
+
* @prop {RouteHandlerOptions} routerClient
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @template Output
|
|
24
|
+
* @template {Capability<StandardSchemaV1>} Cap
|
|
25
|
+
* @param {RouteOptions<Cap, Output>} options
|
|
26
|
+
* @returns {RouteOutput<Cap, Output>}
|
|
27
|
+
*/
|
|
28
|
+
export function route(options) {
|
|
29
|
+
return {
|
|
30
|
+
cap: options.capability,
|
|
31
|
+
fn: async (
|
|
32
|
+
/** @type {RouteHandlerOptions} */ { request, issuer, invocation, store }
|
|
33
|
+
) => {
|
|
34
|
+
const { capability, handler } = options
|
|
35
|
+
|
|
36
|
+
const args = await capability.validate(invocation.payload.args)
|
|
37
|
+
if (args.issues) {
|
|
38
|
+
throw new Error(args.issues.map((issue) => issue.message).join(', '))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// TODO: handle failure
|
|
42
|
+
const result = await handler({ args: args.value, store })
|
|
43
|
+
|
|
44
|
+
return result
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/server.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
2
|
-
import type { Capability } from './capability.js'
|
|
3
|
-
import type { RouteHandlerOptions, RouteOptions, RouteOutput } from './types.js'
|
|
4
|
-
|
|
5
|
-
export function route<Cap extends Capability<StandardSchemaV1>, Output>(
|
|
6
|
-
options: RouteOptions<Cap, Output>
|
|
7
|
-
): RouteOutput<Cap, Output> {
|
|
8
|
-
return {
|
|
9
|
-
cap: options.capability,
|
|
10
|
-
fn: async ({ request, issuer, invocation, store }: RouteHandlerOptions) => {
|
|
11
|
-
const { capability, handler } = options
|
|
12
|
-
|
|
13
|
-
const args = await capability.validate(invocation.payload.args)
|
|
14
|
-
if (args.issues) {
|
|
15
|
-
throw new Error(args.issues.map((issue) => issue.message).join(', '))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// TODO: handle failure
|
|
19
|
-
const result = await handler({ args: args.value, store })
|
|
20
|
-
|
|
21
|
-
return result
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
}
|