@xyo-network/payload-plugin
Advanced tools
Comparing version 2.23.0 to 2.23.1
import { EmptyObject } from '@xyo-network/core'; | ||
import { XyoPayloadValidator, XyoPayloadWrapper } from '@xyo-network/payload'; | ||
import { XyoPayloadPlugin } from './Plugin'; | ||
export declare const defaultXyoPayloadPluginFunctions: <TPayload extends { | ||
schema: string; | ||
previousHash?: string | undefined; | ||
sources?: string[] | undefined; | ||
timestamp?: number | undefined; | ||
}>() => { | ||
validate: (payload: TPayload) => XyoPayloadValidator<TPayload>; | ||
wrap: (payload: TPayload) => XyoPayloadWrapper<TPayload>; | ||
}; | ||
export declare const createXyoPayloadPlugin: <TSchema extends string = string, TPayload extends { | ||
@@ -4,0 +14,0 @@ schema: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createXyoPayloadPlugin = void 0; | ||
exports.createXyoPayloadPlugin = exports.defaultXyoPayloadPluginFunctions = void 0; | ||
const sdk_js_1 = require("@xylabs/sdk-js"); | ||
const payload_1 = require("@xyo-network/payload"); | ||
const createXyoPayloadPlugin = (plugin) => { | ||
return Object.assign(Object.assign({ validate: function (payload) { | ||
const defaultXyoPayloadPluginFunctions = () => { | ||
return { | ||
validate: function (payload) { | ||
return new payload_1.XyoPayloadValidator(payload); | ||
}, wrap: function (payload) { | ||
}, | ||
wrap: function (payload) { | ||
return new payload_1.XyoPayloadWrapper(payload); | ||
} }, plugin), { schema: (0, sdk_js_1.assertEx)(plugin.schema, 'schema field required to cretae plugin') }); | ||
}, | ||
}; | ||
}; | ||
exports.defaultXyoPayloadPluginFunctions = defaultXyoPayloadPluginFunctions; | ||
const createXyoPayloadPlugin = (plugin) => { | ||
return Object.assign(Object.assign(Object.assign({}, (0, exports.defaultXyoPayloadPluginFunctions)()), plugin), { schema: (0, sdk_js_1.assertEx)(plugin.schema, 'schema field required to cretae plugin') }); | ||
}; | ||
exports.createXyoPayloadPlugin = createXyoPayloadPlugin; | ||
//# sourceMappingURL=createPlugin.js.map |
import { XyoValidator } from '@xyo-network/core'; | ||
import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload'; | ||
import { XyoPayloadPlugin } from './Plugin'; | ||
export declare class XyoPayloadPluginResolver<T extends XyoPayloadPlugin<string> = XyoPayloadPlugin<string>> { | ||
protected pluginMap: Map<string, T>; | ||
protected defaultPlugin: T; | ||
constructor(plugins: T[], defaultPlugin: T); | ||
export declare class XyoPayloadPluginResolver { | ||
protected pluginMap: Map<string, XyoPayloadPlugin<string, { | ||
schema: string; | ||
previousHash?: string | undefined; | ||
sources?: string[] | undefined; | ||
timestamp?: number | undefined; | ||
}, import("@xyo-network/core").EmptyObject, import("@xyo-network/core").EmptyObject>>; | ||
protected defaultPlugin: XyoPayloadPlugin<string>; | ||
constructor( | ||
/** @param plugins The initial set of plugins */ | ||
plugins?: XyoPayloadPlugin<string>[], | ||
/** @param defaultPlugin Specifies the plugin to be used if no plugins resolve */ | ||
defaultPlugin?: XyoPayloadPlugin<string, { | ||
schema: string; | ||
previousHash?: string | undefined; | ||
sources?: string[] | undefined; | ||
timestamp?: number | undefined; | ||
}, import("@xyo-network/core").EmptyObject, import("@xyo-network/core").EmptyObject>); | ||
schema: string; | ||
register(plugin: T): void; | ||
resolve(schema?: string): T; | ||
resolve(payload: XyoPayload): T; | ||
register(plugin: XyoPayloadPlugin<string>): this; | ||
resolve(schema?: string): XyoPayloadPlugin<string>; | ||
resolve(payload: XyoPayload): XyoPayloadPlugin<string>; | ||
validate(payload: XyoPayload): XyoValidator<XyoPayload>; | ||
wrap(payload: XyoPayload): XyoPayloadWrapper<XyoPayload>; | ||
/** @description Create list of plugins, optionally filtered by ability to witness/divine */ | ||
plugins(type?: 'witness' | 'diviner'): T[]; | ||
plugins(type?: 'witness' | 'diviner'): XyoPayloadPlugin<string, { | ||
schema: string; | ||
previousHash?: string | undefined; | ||
sources?: string[] | undefined; | ||
timestamp?: number | undefined; | ||
}, import("@xyo-network/core").EmptyObject, import("@xyo-network/core").EmptyObject>[]; | ||
/** @description Create list of schema, optionally filtered by ability to witness/divine */ | ||
@@ -17,0 +36,0 @@ schemas(type?: 'witness' | 'diviner'): string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.XyoPayloadPluginResolver = void 0; | ||
const createPlugin_1 = require("./createPlugin"); | ||
class XyoPayloadPluginResolver { | ||
constructor(plugins, defaultPlugin) { | ||
constructor( | ||
/** @param plugins The initial set of plugins */ | ||
plugins, | ||
/** @param defaultPlugin Specifies the plugin to be used if no plugins resolve */ | ||
defaultPlugin = (0, createPlugin_1.createXyoPayloadPlugin)({ | ||
schema: 'network.xyo.payload', | ||
})) { | ||
this.pluginMap = new Map(); | ||
this.schema = 'network.xyo.payload'; | ||
plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => this.pluginMap.set(plugin.schema, plugin)); | ||
plugins === null || plugins === void 0 ? void 0 : plugins.forEach((plugin) => this.register(plugin)); | ||
this.defaultPlugin = defaultPlugin; | ||
@@ -13,2 +20,3 @@ } | ||
this.pluginMap.set(plugin.schema, plugin); | ||
return this; | ||
} | ||
@@ -15,0 +23,0 @@ resolve(value) { |
import { EmptyObject } from '@xyo-network/core'; | ||
import { XyoPayloadValidator, XyoPayloadWrapper } from '@xyo-network/payload'; | ||
import { XyoPayloadPlugin } from './Plugin'; | ||
export declare const defaultXyoPayloadPluginFunctions: <TPayload extends { | ||
schema: string; | ||
previousHash?: string | undefined; | ||
sources?: string[] | undefined; | ||
timestamp?: number | undefined; | ||
}>() => { | ||
validate: (payload: TPayload) => XyoPayloadValidator<TPayload>; | ||
wrap: (payload: TPayload) => XyoPayloadWrapper<TPayload>; | ||
}; | ||
export declare const createXyoPayloadPlugin: <TSchema extends string = string, TPayload extends { | ||
@@ -4,0 +14,0 @@ schema: string; |
import { assertEx } from '@xylabs/sdk-js'; | ||
import { XyoPayloadValidator, XyoPayloadWrapper } from '@xyo-network/payload'; | ||
export const createXyoPayloadPlugin = (plugin) => { | ||
export const defaultXyoPayloadPluginFunctions = () => { | ||
return { | ||
@@ -11,2 +11,7 @@ validate: function (payload) { | ||
}, | ||
}; | ||
}; | ||
export const createXyoPayloadPlugin = (plugin) => { | ||
return { | ||
...defaultXyoPayloadPluginFunctions(), | ||
...plugin, | ||
@@ -13,0 +18,0 @@ schema: assertEx(plugin.schema, 'schema field required to cretae plugin'), |
import { XyoValidator } from '@xyo-network/core'; | ||
import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload'; | ||
import { XyoPayloadPlugin } from './Plugin'; | ||
export declare class XyoPayloadPluginResolver<T extends XyoPayloadPlugin<string> = XyoPayloadPlugin<string>> { | ||
protected pluginMap: Map<string, T>; | ||
protected defaultPlugin: T; | ||
constructor(plugins: T[], defaultPlugin: T); | ||
export declare class XyoPayloadPluginResolver { | ||
protected pluginMap: Map<string, XyoPayloadPlugin<string, { | ||
schema: string; | ||
previousHash?: string | undefined; | ||
sources?: string[] | undefined; | ||
timestamp?: number | undefined; | ||
}, import("@xyo-network/core").EmptyObject, import("@xyo-network/core").EmptyObject>>; | ||
protected defaultPlugin: XyoPayloadPlugin<string>; | ||
constructor( | ||
/** @param plugins The initial set of plugins */ | ||
plugins?: XyoPayloadPlugin<string>[], | ||
/** @param defaultPlugin Specifies the plugin to be used if no plugins resolve */ | ||
defaultPlugin?: XyoPayloadPlugin<string, { | ||
schema: string; | ||
previousHash?: string | undefined; | ||
sources?: string[] | undefined; | ||
timestamp?: number | undefined; | ||
}, import("@xyo-network/core").EmptyObject, import("@xyo-network/core").EmptyObject>); | ||
schema: string; | ||
register(plugin: T): void; | ||
resolve(schema?: string): T; | ||
resolve(payload: XyoPayload): T; | ||
register(plugin: XyoPayloadPlugin<string>): this; | ||
resolve(schema?: string): XyoPayloadPlugin<string>; | ||
resolve(payload: XyoPayload): XyoPayloadPlugin<string>; | ||
validate(payload: XyoPayload): XyoValidator<XyoPayload>; | ||
wrap(payload: XyoPayload): XyoPayloadWrapper<XyoPayload>; | ||
/** @description Create list of plugins, optionally filtered by ability to witness/divine */ | ||
plugins(type?: 'witness' | 'diviner'): T[]; | ||
plugins(type?: 'witness' | 'diviner'): XyoPayloadPlugin<string, { | ||
schema: string; | ||
previousHash?: string | undefined; | ||
sources?: string[] | undefined; | ||
timestamp?: number | undefined; | ||
}, import("@xyo-network/core").EmptyObject, import("@xyo-network/core").EmptyObject>[]; | ||
/** @description Create list of schema, optionally filtered by ability to witness/divine */ | ||
@@ -17,0 +36,0 @@ schemas(type?: 'witness' | 'diviner'): string[]; |
@@ -0,6 +1,13 @@ | ||
import { createXyoPayloadPlugin } from './createPlugin'; | ||
export class XyoPayloadPluginResolver { | ||
pluginMap = new Map(); | ||
defaultPlugin; | ||
constructor(plugins, defaultPlugin) { | ||
plugins?.forEach((plugin) => this.pluginMap.set(plugin.schema, plugin)); | ||
constructor( | ||
/** @param plugins The initial set of plugins */ | ||
plugins, | ||
/** @param defaultPlugin Specifies the plugin to be used if no plugins resolve */ | ||
defaultPlugin = createXyoPayloadPlugin({ | ||
schema: 'network.xyo.payload', | ||
})) { | ||
plugins?.forEach((plugin) => this.register(plugin)); | ||
this.defaultPlugin = defaultPlugin; | ||
@@ -11,2 +18,3 @@ } | ||
this.pluginMap.set(plugin.schema, plugin); | ||
return this; | ||
} | ||
@@ -13,0 +21,0 @@ resolve(value) { |
@@ -14,5 +14,5 @@ { | ||
"@xylabs/sdk-js": "^2.6.2", | ||
"@xyo-network/core": "^2.23.0", | ||
"@xyo-network/payload": "^2.23.0", | ||
"@xyo-network/witness": "^2.23.0", | ||
"@xyo-network/core": "^2.23.1", | ||
"@xyo-network/payload": "^2.23.1", | ||
"@xyo-network/witness": "^2.23.1", | ||
"tslib": "^2.4.0" | ||
@@ -53,4 +53,4 @@ }, | ||
"types": "dist/esm/index.d.ts", | ||
"version": "2.23.0", | ||
"version": "2.23.1", | ||
"packageManager": "yarn@3.1.1" | ||
} |
@@ -7,2 +7,13 @@ import { assertEx } from '@xylabs/sdk-js' | ||
export const defaultXyoPayloadPluginFunctions = <TPayload extends XyoPayload>() => { | ||
return { | ||
validate: function (payload: TPayload): XyoPayloadValidator<TPayload> { | ||
return new XyoPayloadValidator<TPayload>(payload) | ||
}, | ||
wrap: function (payload: TPayload): XyoPayloadWrapper<TPayload> { | ||
return new XyoPayloadWrapper(payload) | ||
}, | ||
} | ||
} | ||
export const createXyoPayloadPlugin = < | ||
@@ -17,8 +28,3 @@ TSchema extends string = string, | ||
return { | ||
validate: function (payload: TPayload): XyoPayloadValidator<TPayload> { | ||
return new XyoPayloadValidator<TPayload>(payload) | ||
}, | ||
wrap: function (payload: TPayload): XyoPayloadWrapper<TPayload> { | ||
return new XyoPayloadWrapper(payload) | ||
}, | ||
...defaultXyoPayloadPluginFunctions<TPayload>(), | ||
...plugin, | ||
@@ -25,0 +31,0 @@ schema: assertEx(plugin.schema, 'schema field required to cretae plugin'), |
import { XyoValidator } from '@xyo-network/core' | ||
import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload' | ||
import { createXyoPayloadPlugin } from './createPlugin' | ||
import { XyoPayloadPlugin } from './Plugin' | ||
export class XyoPayloadPluginResolver<T extends XyoPayloadPlugin<string> = XyoPayloadPlugin<string>> { | ||
protected pluginMap = new Map<string, T>() | ||
protected defaultPlugin: T | ||
export class XyoPayloadPluginResolver { | ||
protected pluginMap = new Map<string, XyoPayloadPlugin<string>>() | ||
protected defaultPlugin: XyoPayloadPlugin<string> | ||
constructor(plugins: T[], defaultPlugin: T) { | ||
plugins?.forEach((plugin) => this.pluginMap.set(plugin.schema, plugin)) | ||
constructor( | ||
/** @param plugins The initial set of plugins */ | ||
plugins?: XyoPayloadPlugin<string>[], | ||
/** @param defaultPlugin Specifies the plugin to be used if no plugins resolve */ | ||
defaultPlugin = createXyoPayloadPlugin<string, XyoPayload>({ | ||
schema: 'network.xyo.payload', | ||
}) | ||
) { | ||
plugins?.forEach((plugin) => this.register(plugin)) | ||
this.defaultPlugin = defaultPlugin | ||
@@ -16,9 +24,10 @@ } | ||
public register(plugin: T) { | ||
public register(plugin: XyoPayloadPlugin<string>) { | ||
this.pluginMap.set(plugin.schema, plugin) | ||
return this | ||
} | ||
public resolve(schema?: string): T | ||
public resolve(payload: XyoPayload): T | ||
public resolve(value: XyoPayload | string | undefined): T { | ||
public resolve(schema?: string): XyoPayloadPlugin<string> | ||
public resolve(payload: XyoPayload): XyoPayloadPlugin<string> | ||
public resolve(value: XyoPayload | string | undefined): XyoPayloadPlugin<string> { | ||
return value ? this.pluginMap.get(typeof value === 'string' ? value : value.schema) ?? this.defaultPlugin : this.defaultPlugin | ||
@@ -37,3 +46,3 @@ } | ||
public plugins(type?: 'witness' | 'diviner') { | ||
const result: T[] = [] | ||
const result: XyoPayloadPlugin<string>[] = [] | ||
this.pluginMap.forEach((value) => { | ||
@@ -40,0 +49,0 @@ if (type === 'witness' && !value.witness) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
124292
3851
0
Updated@xyo-network/core@^2.23.1
Updated@xyo-network/payload@^2.23.1
Updated@xyo-network/witness@^2.23.1