Commit 0e252e9 1 parent a0efe18 commit 0e252e9 Copy full SHA for 0e252e9
File tree 19 files changed +210
-31
lines changed
19 files changed +210
-31
lines changed Original file line number Diff line number Diff line change 6
6
"files" : [" dist" ],
7
7
"exports" : {
8
8
"." : {
9
- "default" : " ./dist/index.js" ,
10
- "types" : " ./dist/index.d.ts"
9
+ "default" : " ./dist/core/ index.js" ,
10
+ "types" : " ./dist/core/ index.d.ts"
11
11
}
12
12
},
13
13
19
19
},
20
20
21
21
"devDependencies" : {
22
- "@sirutils/builder" : " workspace:*"
22
+ "@sirutils/builder" : " workspace:*" ,
23
+ "cbor-x" : " ^1.6.0"
23
24
},
24
25
"dependencies" : {
25
26
"@sirutils/core" : " workspace:*" ,
26
27
"@sirutils/schema" : " workspace:*" ,
27
28
"@sirutils/toolbox" : " workspace:*"
29
+ },
30
+ "peerDependencies" : {
31
+ "cbor-x" : " ^1.6.0"
28
32
}
29
33
}
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ import type { Duplex } from 'node:stream'
2
+ import type { BlobType } from '@sirutils/core'
3
+
4
+ import type { createNuts } from '../plugin/create'
5
+ import type { NutsTags } from '../tag'
6
+
7
+ declare global {
8
+ namespace Sirutils {
9
+ interface CustomErrors {
10
+ nuts : NutsTags
11
+ }
12
+
13
+ interface PluginDefinitions {
14
+ nuts : Sirutils . PluginSystem . ExtractDefinition < typeof createNuts >
15
+ 'nuts-serializer' : Sirutils . PluginSystem . Context < BlobType , Sirutils . Nuts . SerializerApi >
16
+ }
17
+
18
+ namespace Nuts {
19
+ interface Options {
20
+ id ?: string
21
+ environment ?: 'production' | 'development' | 'test'
22
+
23
+ port ?: string
24
+ host ?: string
25
+ logs ?: boolean
26
+ }
27
+
28
+ interface Broker { }
29
+
30
+ interface BaseApi { }
31
+ interface BrokerApi {
32
+ broker : Sirutils . Nuts . Broker
33
+ }
34
+
35
+ type Context = Sirutils . PluginSystem . Context <
36
+ Sirutils . Nuts . Options ,
37
+ Sirutils . Nuts . BaseApi & Sirutils . Nuts . BrokerApi
38
+ >
39
+
40
+ interface SerializerApi {
41
+ encode : < T = unknown > ( data : T ) => Buffer
42
+ decode : < T = unknown > ( data : string | Buffer ) => T
43
+
44
+ encodeStream : ( ) => Duplex
45
+ decodeStream : ( ) => Duplex
46
+ }
47
+ }
48
+ }
49
+ }
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ import { createPlugin } from '@sirutils/core'
2
+
3
+ import { nutsTags } from '../tag'
4
+ import { brokerActions } from './internal/broker'
5
+
6
+ export const createNuts = createPlugin < Sirutils . Nuts . Options , Sirutils . Nuts . BaseApi > (
7
+ {
8
+ name : 'nuts' ,
9
+ version : '0.2.3' ,
10
+
11
+ dependencies : {
12
+ 'nuts-serializer' : '*' ,
13
+ } ,
14
+ } ,
15
+ ctx => {
16
+ return {
17
+ broker : { } ,
18
+ }
19
+ } ,
20
+ nutsTags . plugin
21
+ )
22
+ . register ( brokerActions )
23
+ . lock ( )
Original file line number Diff line number Diff line change
1
+ import { createActions } from '@sirutils/core'
2
+
3
+ import { nutsTags } from '../../tag'
4
+
5
+ export const brokerActions = createActions (
6
+ ( context : Sirutils . Nuts . Context ) : Sirutils . Nuts . BrokerApi => {
7
+ const serializer = context . lookup ( 'nuts-serializer' )
8
+
9
+ return {
10
+ broker : { } ,
11
+ }
12
+ } ,
13
+ nutsTags . broker
14
+ )
Original file line number Diff line number Diff line change 1
- import { createTag } from './internal/tag'
1
+ import { tagBuilder } from '@sirutils/core'
2
+
3
+ export const createTag = tagBuilder ( '@sirutils/nuts' )
2
4
3
5
export const nutsTags = {
4
6
// internal
5
7
logger : createTag ( 'logger' ) ,
6
8
7
9
plugin : createTag ( 'plugin' ) ,
10
+ broker : createTag ( 'broker' ) ,
8
11
} as const
9
12
10
13
export type NutsTags = ( typeof nutsTags ) [ keyof typeof nutsTags ]
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import type { Options as CborOptions , Decoder , Encoder } from 'cbor-x'
2
+
3
+ import type { createCbor } from '../plugin/create'
4
+ import type { CborTags } from '../tag'
5
+
6
+ declare global {
7
+ namespace Sirutils {
8
+ interface CustomErrors {
9
+ 'nuts-cbor' : CborTags
10
+ }
11
+
12
+ interface PluginDefinitions {
13
+ 'nuts-cbor' : Sirutils . PluginSystem . ExtractDefinition < typeof createCbor >
14
+ }
15
+
16
+ namespace Nuts {
17
+ namespace Cbor {
18
+ interface Options extends CborOptions { }
19
+
20
+ interface BaseApi {
21
+ $encoder : Encoder
22
+ $decoder : Decoder
23
+ }
24
+
25
+ interface SerializerApi extends Sirutils . Nuts . SerializerApi { }
26
+
27
+ type Context = Sirutils . PluginSystem . Context <
28
+ Sirutils . Nuts . Cbor . Options ,
29
+ Sirutils . Nuts . Cbor . BaseApi & Sirutils . Nuts . Cbor . SerializerApi
30
+ >
31
+ }
32
+ }
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ /// <reference types="@sirutils/core" />
2
+ /// <reference types="@sirutils/toolbox" />
3
+ /// <reference types="@sirutils/schema" />
4
+
5
+ import '../../core'
6
+ import './cbor'
Original file line number Diff line number Diff line change
1
+ import './definitions'
2
+
3
+ export * from './plugin/create'
4
+
5
+ export * from './tag'
Original file line number Diff line number Diff line change
1
+ import { createPlugin } from '@sirutils/core'
2
+ import { Decoder , Encoder } from 'cbor-x'
3
+
4
+ import { cborTags } from '../tag'
5
+ import { serializerApiActions } from './internal/api'
6
+
7
+ export const createCbor = createPlugin < Sirutils . Nuts . Cbor . Options , Sirutils . Nuts . Cbor . BaseApi > (
8
+ {
9
+ name : 'nuts-serializer' , // cbor
10
+ version : '0.2.3' ,
11
+
12
+ dependencies : { } ,
13
+ } ,
14
+ context => {
15
+ const $encoder = new Encoder ( context . options )
16
+ const $decoder = new Decoder ( context . options )
17
+
18
+ return {
19
+ $encoder,
20
+ $decoder,
21
+ }
22
+ } ,
23
+ cborTags . plugin ,
24
+ { }
25
+ )
26
+ . register ( serializerApiActions )
27
+ . lock ( )
Original file line number Diff line number Diff line change
1
+ import { createActions } from '@sirutils/core'
2
+ import { DecoderStream , EncoderStream } from 'cbor-x'
3
+
4
+ import { cborTags } from '../../tag'
5
+
6
+ export const serializerApiActions = createActions (
7
+ ( context : Sirutils . Nuts . Cbor . Context ) : Sirutils . Nuts . Cbor . SerializerApi => {
8
+ return {
9
+ encode : data => {
10
+ return context . api . $encoder . encode ( data )
11
+ } ,
12
+ decode : data => {
13
+ if ( typeof data === 'string' ) {
14
+ return context . api . $decoder . decode ( Buffer . from ( data ) )
15
+ }
16
+
17
+ return context . api . $decoder . decode ( data )
18
+ } ,
19
+
20
+ encodeStream : ( ) => new EncoderStream ( context . options ) ,
21
+ decodeStream : ( ) => new DecoderStream ( context . options ) ,
22
+ }
23
+ } ,
24
+ cborTags . api
25
+ )
Original file line number Diff line number Diff line change
1
+ import { tagBuilder } from '@sirutils/core'
2
+
3
+ export const createTag = tagBuilder ( '@sirutils/nuts#cbor' )
4
+
5
+ export const cborTags = {
6
+ plugin : createTag ( 'plugin' ) ,
7
+
8
+ api : createTag ( 'api' ) ,
9
+ } as const
10
+
11
+ export type CborTags = ( typeof cborTags ) [ keyof typeof cborTags ]
Original file line number Diff line number Diff line change 1
- import { createNuts } from '../src'
1
+ import { createNuts } from '../src/core'
2
+ import { createCbor } from '../src/serializer-cbor'
2
3
3
- export const nuts = await createNuts ( )
4
+ const [ serializer ] = await Promise . all ( [ createCbor ( ) ] )
5
+
6
+ export const nuts = await createNuts ( { } , serializer )
You can’t perform that action at this time.
0 commit comments