@xyo-network/payload-plugin 2.79.4 → 2.79.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/node/index.cjs +105 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.js +13 -42
- package/dist/node/index.js.map +1 -1
- package/package.json +14 -14
- package/dist/node/index.mjs +0 -76
- package/dist/node/index.mjs.map +0 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
PayloadPluginResolver: () => PayloadPluginResolver,
|
|
24
|
+
createPayloadPlugin: () => createPayloadPlugin,
|
|
25
|
+
defaultPayloadPluginFunctions: () => defaultPayloadPluginFunctions
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
|
|
29
|
+
// src/createPlugin.ts
|
|
30
|
+
var import_assert = require("@xylabs/assert");
|
|
31
|
+
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
32
|
+
var import_payload_validator = require("@xyo-network/payload-validator");
|
|
33
|
+
var import_payload_wrapper = require("@xyo-network/payload-wrapper");
|
|
34
|
+
var defaultPayloadPluginFunctions = (schema) => {
|
|
35
|
+
return {
|
|
36
|
+
build: () => {
|
|
37
|
+
return new import_payload_builder.PayloadBuilder({ schema });
|
|
38
|
+
},
|
|
39
|
+
schema,
|
|
40
|
+
validate: (payload) => {
|
|
41
|
+
return new import_payload_validator.PayloadValidator(payload);
|
|
42
|
+
},
|
|
43
|
+
wrap: (payload) => {
|
|
44
|
+
return import_payload_wrapper.PayloadWrapper.wrap(payload);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var createPayloadPlugin = (plugin) => {
|
|
49
|
+
return {
|
|
50
|
+
...defaultPayloadPluginFunctions((0, import_assert.assertEx)(plugin.schema, "schema field required to create plugin")),
|
|
51
|
+
...plugin
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/Resolver.ts
|
|
56
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
57
|
+
var PayloadPluginResolver = class {
|
|
58
|
+
schema = import_payload_model.PayloadSchema;
|
|
59
|
+
_plugins = {};
|
|
60
|
+
defaultPlugin;
|
|
61
|
+
constructor(plugins, defaultPlugin = createPayloadPlugin({
|
|
62
|
+
schema: import_payload_model.PayloadSchema
|
|
63
|
+
})) {
|
|
64
|
+
plugins == null ? void 0 : plugins.forEach((plugin) => this.register(plugin));
|
|
65
|
+
this.defaultPlugin = defaultPlugin;
|
|
66
|
+
}
|
|
67
|
+
/** @description Create list of plugins, optionally filtered by ability to witness/divine */
|
|
68
|
+
plugins() {
|
|
69
|
+
const result = [];
|
|
70
|
+
Object.values(this._plugins).forEach((value) => {
|
|
71
|
+
result.push(value);
|
|
72
|
+
});
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
register(plugin) {
|
|
76
|
+
this._plugins[plugin.schema] = plugin;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
resolve(value) {
|
|
80
|
+
return value ? this._plugins[typeof value === "string" ? value : value.schema] ?? this.defaultPlugin : this.defaultPlugin;
|
|
81
|
+
}
|
|
82
|
+
/** @description Create list of schema, optionally filtered by ability to witness/divine */
|
|
83
|
+
schemas() {
|
|
84
|
+
const result = [];
|
|
85
|
+
Object.values(this._plugins).forEach((value) => {
|
|
86
|
+
result.push(value.schema);
|
|
87
|
+
});
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
validate(payload) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
return (_b = (_a = this.resolve(payload)).validate) == null ? void 0 : _b.call(_a, payload);
|
|
93
|
+
}
|
|
94
|
+
wrap(payload) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
return (_b = (_a = this.resolve(payload)).wrap) == null ? void 0 : _b.call(_a, payload);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
PayloadPluginResolver,
|
|
102
|
+
createPayloadPlugin,
|
|
103
|
+
defaultPayloadPluginFunctions
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/createPlugin.ts","../../src/Resolver.ts"],"sourcesContent":["export * from './createPlugin'\nexport * from './Plugin'\nexport * from './Resolver'\n","import { assertEx } from '@xylabs/assert'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadValidator } from '@xyo-network/payload-validator'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { PayloadPlugin } from './Plugin'\n\nexport const defaultPayloadPluginFunctions = <T extends Payload>(schema: string): PayloadPlugin<T> => {\n return {\n build: (): PayloadBuilder<T> => {\n return new PayloadBuilder<T>({ schema })\n },\n schema,\n validate: (payload: Payload): PayloadValidator<T> => {\n return new PayloadValidator<T>(payload as T)\n },\n wrap: (payload: Payload): PayloadWrapper<T> => {\n return PayloadWrapper.wrap<T>(payload as T)\n },\n }\n}\n\nexport const createPayloadPlugin = <TPayload extends Payload = Payload>(plugin: PayloadPlugin<TPayload>): PayloadPlugin<TPayload> => {\n return {\n ...defaultPayloadPluginFunctions<TPayload>(assertEx(plugin.schema, 'schema field required to create plugin')),\n ...plugin,\n }\n}\n","import { Validator } from '@xyo-network/core'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { createPayloadPlugin } from './createPlugin'\nimport { PayloadPlugin } from './Plugin'\n\nexport class PayloadPluginResolver {\n schema = PayloadSchema\n\n protected _plugins: Record<string, PayloadPlugin> = {}\n protected defaultPlugin: PayloadPlugin\n\n constructor(\n /** @param plugins The initial set of plugins */\n plugins?: PayloadPlugin<Payload>[],\n /** @param defaultPlugin Specifies the plugin to be used if no plugins resolve */\n defaultPlugin = createPayloadPlugin<Payload>({\n schema: PayloadSchema,\n }),\n ) {\n plugins?.forEach((plugin) => this.register(plugin))\n this.defaultPlugin = defaultPlugin\n }\n\n /** @description Create list of plugins, optionally filtered by ability to witness/divine */\n plugins() {\n const result: PayloadPlugin[] = []\n Object.values(this._plugins).forEach((value) => {\n result.push(value)\n })\n return result\n }\n\n register<TPlugin extends PayloadPlugin = PayloadPlugin>(plugin: TPlugin) {\n this._plugins[plugin.schema] = plugin\n\n return this\n }\n\n resolve(schema?: string): PayloadPlugin\n resolve(payload: Payload): PayloadPlugin\n resolve(value: Payload | string | undefined): PayloadPlugin {\n return value ? this._plugins[typeof value === 'string' ? value : value.schema] ?? this.defaultPlugin : this.defaultPlugin\n }\n\n /** @description Create list of schema, optionally filtered by ability to witness/divine */\n schemas() {\n const result: string[] = []\n Object.values(this._plugins).forEach((value) => {\n result.push(value.schema)\n })\n return result\n }\n\n validate(payload: Payload): Validator<Payload> | undefined {\n return this.resolve(payload).validate?.(payload)\n }\n\n wrap(payload: Payload): PayloadWrapper<Payload> | undefined {\n return this.resolve(payload).wrap?.(payload)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,6BAA+B;AAE/B,+BAAiC;AACjC,6BAA+B;AAIxB,IAAM,gCAAgC,CAAoB,WAAqC;AACpG,SAAO;AAAA,IACL,OAAO,MAAyB;AAC9B,aAAO,IAAI,sCAAkB,EAAE,OAAO,CAAC;AAAA,IACzC;AAAA,IACA;AAAA,IACA,UAAU,CAAC,YAA0C;AACnD,aAAO,IAAI,0CAAoB,OAAY;AAAA,IAC7C;AAAA,IACA,MAAM,CAAC,YAAwC;AAC7C,aAAO,sCAAe,KAAQ,OAAY;AAAA,IAC5C;AAAA,EACF;AACF;AAEO,IAAM,sBAAsB,CAAqC,WAA6D;AACnI,SAAO;AAAA,IACL,GAAG,kCAAwC,wBAAS,OAAO,QAAQ,wCAAwC,CAAC;AAAA,IAC5G,GAAG;AAAA,EACL;AACF;;;AC3BA,2BAAuC;AAMhC,IAAM,wBAAN,MAA4B;AAAA,EACjC,SAAS;AAAA,EAEC,WAA0C,CAAC;AAAA,EAC3C;AAAA,EAEV,YAEE,SAEA,gBAAgB,oBAA6B;AAAA,IAC3C,QAAQ;AAAA,EACV,CAAC,GACD;AACA,uCAAS,QAAQ,CAAC,WAAW,KAAK,SAAS,MAAM;AACjD,SAAK,gBAAgB;AAAA,EACvB;AAAA;AAAA,EAGA,UAAU;AACR,UAAM,SAA0B,CAAC;AACjC,WAAO,OAAO,KAAK,QAAQ,EAAE,QAAQ,CAAC,UAAU;AAC9C,aAAO,KAAK,KAAK;AAAA,IACnB,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,SAAwD,QAAiB;AACvE,SAAK,SAAS,OAAO,MAAM,IAAI;AAE/B,WAAO;AAAA,EACT;AAAA,EAIA,QAAQ,OAAoD;AAC1D,WAAO,QAAQ,KAAK,SAAS,OAAO,UAAU,WAAW,QAAQ,MAAM,MAAM,KAAK,KAAK,gBAAgB,KAAK;AAAA,EAC9G;AAAA;AAAA,EAGA,UAAU;AACR,UAAM,SAAmB,CAAC;AAC1B,WAAO,OAAO,KAAK,QAAQ,EAAE,QAAQ,CAAC,UAAU;AAC9C,aAAO,KAAK,MAAM,MAAM;AAAA,IAC1B,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,SAAkD;AAvD7D;AAwDI,YAAO,gBAAK,QAAQ,OAAO,GAAE,aAAtB,4BAAiC;AAAA,EAC1C;AAAA,EAEA,KAAK,SAAuD;AA3D9D;AA4DI,YAAO,gBAAK,QAAQ,OAAO,GAAE,SAAtB,4BAA6B;AAAA,EACtC;AACF;","names":[]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,65 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
PayloadPluginResolver: () => PayloadPluginResolver,
|
|
24
|
-
createPayloadPlugin: () => createPayloadPlugin,
|
|
25
|
-
defaultPayloadPluginFunctions: () => defaultPayloadPluginFunctions
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(src_exports);
|
|
28
|
-
|
|
29
1
|
// src/createPlugin.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
import { assertEx } from "@xylabs/assert";
|
|
3
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
4
|
+
import { PayloadValidator } from "@xyo-network/payload-validator";
|
|
5
|
+
import { PayloadWrapper } from "@xyo-network/payload-wrapper";
|
|
34
6
|
var defaultPayloadPluginFunctions = (schema) => {
|
|
35
7
|
return {
|
|
36
8
|
build: () => {
|
|
37
|
-
return new
|
|
9
|
+
return new PayloadBuilder({ schema });
|
|
38
10
|
},
|
|
39
11
|
schema,
|
|
40
12
|
validate: (payload) => {
|
|
41
|
-
return new
|
|
13
|
+
return new PayloadValidator(payload);
|
|
42
14
|
},
|
|
43
15
|
wrap: (payload) => {
|
|
44
|
-
return
|
|
16
|
+
return PayloadWrapper.wrap(payload);
|
|
45
17
|
}
|
|
46
18
|
};
|
|
47
19
|
};
|
|
48
20
|
var createPayloadPlugin = (plugin) => {
|
|
49
21
|
return {
|
|
50
|
-
...defaultPayloadPluginFunctions(
|
|
22
|
+
...defaultPayloadPluginFunctions(assertEx(plugin.schema, "schema field required to create plugin")),
|
|
51
23
|
...plugin
|
|
52
24
|
};
|
|
53
25
|
};
|
|
54
26
|
|
|
55
27
|
// src/Resolver.ts
|
|
56
|
-
|
|
28
|
+
import { PayloadSchema } from "@xyo-network/payload-model";
|
|
57
29
|
var PayloadPluginResolver = class {
|
|
58
|
-
schema =
|
|
30
|
+
schema = PayloadSchema;
|
|
59
31
|
_plugins = {};
|
|
60
32
|
defaultPlugin;
|
|
61
33
|
constructor(plugins, defaultPlugin = createPayloadPlugin({
|
|
62
|
-
schema:
|
|
34
|
+
schema: PayloadSchema
|
|
63
35
|
})) {
|
|
64
36
|
plugins == null ? void 0 : plugins.forEach((plugin) => this.register(plugin));
|
|
65
37
|
this.defaultPlugin = defaultPlugin;
|
|
@@ -96,10 +68,9 @@ var PayloadPluginResolver = class {
|
|
|
96
68
|
return (_b = (_a = this.resolve(payload)).wrap) == null ? void 0 : _b.call(_a, payload);
|
|
97
69
|
}
|
|
98
70
|
};
|
|
99
|
-
|
|
100
|
-
0 && (module.exports = {
|
|
71
|
+
export {
|
|
101
72
|
PayloadPluginResolver,
|
|
102
73
|
createPayloadPlugin,
|
|
103
74
|
defaultPayloadPluginFunctions
|
|
104
|
-
}
|
|
75
|
+
};
|
|
105
76
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/createPlugin.ts","../../src/Resolver.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadValidator } from '@xyo-network/payload-validator'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { PayloadPlugin } from './Plugin'\n\nexport const defaultPayloadPluginFunctions = <T extends Payload>(schema: string): PayloadPlugin<T> => {\n return {\n build: (): PayloadBuilder<T> => {\n return new PayloadBuilder<T>({ schema })\n },\n schema,\n validate: (payload: Payload): PayloadValidator<T> => {\n return new PayloadValidator<T>(payload as T)\n },\n wrap: (payload: Payload): PayloadWrapper<T> => {\n return PayloadWrapper.wrap<T>(payload as T)\n },\n }\n}\n\nexport const createPayloadPlugin = <TPayload extends Payload = Payload>(plugin: PayloadPlugin<TPayload>): PayloadPlugin<TPayload> => {\n return {\n ...defaultPayloadPluginFunctions<TPayload>(assertEx(plugin.schema, 'schema field required to create plugin')),\n ...plugin,\n }\n}\n","import { Validator } from '@xyo-network/core'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { createPayloadPlugin } from './createPlugin'\nimport { PayloadPlugin } from './Plugin'\n\nexport class PayloadPluginResolver {\n schema = PayloadSchema\n\n protected _plugins: Record<string, PayloadPlugin> = {}\n protected defaultPlugin: PayloadPlugin\n\n constructor(\n /** @param plugins The initial set of plugins */\n plugins?: PayloadPlugin<Payload>[],\n /** @param defaultPlugin Specifies the plugin to be used if no plugins resolve */\n defaultPlugin = createPayloadPlugin<Payload>({\n schema: PayloadSchema,\n }),\n ) {\n plugins?.forEach((plugin) => this.register(plugin))\n this.defaultPlugin = defaultPlugin\n }\n\n /** @description Create list of plugins, optionally filtered by ability to witness/divine */\n plugins() {\n const result: PayloadPlugin[] = []\n Object.values(this._plugins).forEach((value) => {\n result.push(value)\n })\n return result\n }\n\n register<TPlugin extends PayloadPlugin = PayloadPlugin>(plugin: TPlugin) {\n this._plugins[plugin.schema] = plugin\n\n return this\n }\n\n resolve(schema?: string): PayloadPlugin\n resolve(payload: Payload): PayloadPlugin\n resolve(value: Payload | string | undefined): PayloadPlugin {\n return value ? this._plugins[typeof value === 'string' ? value : value.schema] ?? this.defaultPlugin : this.defaultPlugin\n }\n\n /** @description Create list of schema, optionally filtered by ability to witness/divine */\n schemas() {\n const result: string[] = []\n Object.values(this._plugins).forEach((value) => {\n result.push(value.schema)\n })\n return result\n }\n\n validate(payload: Payload): Validator<Payload> | undefined {\n return this.resolve(payload).validate?.(payload)\n }\n\n wrap(payload: Payload): PayloadWrapper<Payload> | undefined {\n return this.resolve(payload).wrap?.(payload)\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAE/B,SAAS,wBAAwB;AACjC,SAA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AC9C,aAAO,KAAK,MAAM,MAAM;AAAA,IAC1B,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,SAAkD;AAvD7D;AAwDI,YAAO,gBAAK,QAAQ,OAAO,GAAE,aAAtB,4BAAiC;AAAA,EAC1C;AAAA,EAEA,KAAK,SAAuD;AA3D9D;AA4DI,YAAO,gBAAK,QAAQ,OAAO,GAAE,SAAtB,4BAA6B;AAAA,EACtC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/assert": "^2.13.
|
|
14
|
-
"@xyo-network/core": "~2.79.
|
|
15
|
-
"@xyo-network/payload-builder": "~2.79.
|
|
16
|
-
"@xyo-network/payload-model": "~2.79.
|
|
17
|
-
"@xyo-network/payload-validator": "~2.79.
|
|
18
|
-
"@xyo-network/payload-wrapper": "~2.79.
|
|
13
|
+
"@xylabs/assert": "^2.13.8",
|
|
14
|
+
"@xyo-network/core": "~2.79.5",
|
|
15
|
+
"@xyo-network/payload-builder": "~2.79.5",
|
|
16
|
+
"@xyo-network/payload-model": "~2.79.5",
|
|
17
|
+
"@xyo-network/payload-validator": "~2.79.5",
|
|
18
|
+
"@xyo-network/payload-wrapper": "~2.79.5"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@xylabs/ts-scripts-yarn3": "^3.1.21",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"typescript": "^5.2.2"
|
|
24
24
|
},
|
|
25
25
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
26
|
-
"docs": "dist/docs.json",
|
|
27
26
|
"exports": {
|
|
28
27
|
".": {
|
|
29
28
|
"browser": {
|
|
@@ -38,19 +37,21 @@
|
|
|
38
37
|
},
|
|
39
38
|
"node": {
|
|
40
39
|
"require": {
|
|
41
|
-
"types": "./dist/node/index.d.
|
|
42
|
-
"default": "./dist/node/index.
|
|
40
|
+
"types": "./dist/node/index.d.cts",
|
|
41
|
+
"default": "./dist/node/index.cjs"
|
|
43
42
|
},
|
|
44
43
|
"import": {
|
|
45
44
|
"types": "./dist/node/index.d.mts",
|
|
46
|
-
"default": "./dist/node/index.
|
|
45
|
+
"default": "./dist/node/index.js"
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
},
|
|
50
49
|
"./package.json": "./package.json"
|
|
51
50
|
},
|
|
52
|
-
"main": "dist/node/index.
|
|
53
|
-
"module": "dist/node/index.
|
|
51
|
+
"main": "dist/node/index.cjs",
|
|
52
|
+
"module": "dist/node/index.js",
|
|
53
|
+
"types": "dist/node/index.d.mts",
|
|
54
|
+
"type": "module",
|
|
54
55
|
"homepage": "https://xyo.network",
|
|
55
56
|
"license": "LGPL-3.0-only",
|
|
56
57
|
"publishConfig": {
|
|
@@ -61,6 +62,5 @@
|
|
|
61
62
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
62
63
|
},
|
|
63
64
|
"sideEffects": false,
|
|
64
|
-
"
|
|
65
|
-
"version": "2.79.4"
|
|
65
|
+
"version": "2.79.5"
|
|
66
66
|
}
|
package/dist/node/index.mjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// src/createPlugin.ts
|
|
2
|
-
import { assertEx } from "@xylabs/assert";
|
|
3
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
4
|
-
import { PayloadValidator } from "@xyo-network/payload-validator";
|
|
5
|
-
import { PayloadWrapper } from "@xyo-network/payload-wrapper";
|
|
6
|
-
var defaultPayloadPluginFunctions = (schema) => {
|
|
7
|
-
return {
|
|
8
|
-
build: () => {
|
|
9
|
-
return new PayloadBuilder({ schema });
|
|
10
|
-
},
|
|
11
|
-
schema,
|
|
12
|
-
validate: (payload) => {
|
|
13
|
-
return new PayloadValidator(payload);
|
|
14
|
-
},
|
|
15
|
-
wrap: (payload) => {
|
|
16
|
-
return PayloadWrapper.wrap(payload);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
var createPayloadPlugin = (plugin) => {
|
|
21
|
-
return {
|
|
22
|
-
...defaultPayloadPluginFunctions(assertEx(plugin.schema, "schema field required to create plugin")),
|
|
23
|
-
...plugin
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// src/Resolver.ts
|
|
28
|
-
import { PayloadSchema } from "@xyo-network/payload-model";
|
|
29
|
-
var PayloadPluginResolver = class {
|
|
30
|
-
schema = PayloadSchema;
|
|
31
|
-
_plugins = {};
|
|
32
|
-
defaultPlugin;
|
|
33
|
-
constructor(plugins, defaultPlugin = createPayloadPlugin({
|
|
34
|
-
schema: PayloadSchema
|
|
35
|
-
})) {
|
|
36
|
-
plugins == null ? void 0 : plugins.forEach((plugin) => this.register(plugin));
|
|
37
|
-
this.defaultPlugin = defaultPlugin;
|
|
38
|
-
}
|
|
39
|
-
/** @description Create list of plugins, optionally filtered by ability to witness/divine */
|
|
40
|
-
plugins() {
|
|
41
|
-
const result = [];
|
|
42
|
-
Object.values(this._plugins).forEach((value) => {
|
|
43
|
-
result.push(value);
|
|
44
|
-
});
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
register(plugin) {
|
|
48
|
-
this._plugins[plugin.schema] = plugin;
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
resolve(value) {
|
|
52
|
-
return value ? this._plugins[typeof value === "string" ? value : value.schema] ?? this.defaultPlugin : this.defaultPlugin;
|
|
53
|
-
}
|
|
54
|
-
/** @description Create list of schema, optionally filtered by ability to witness/divine */
|
|
55
|
-
schemas() {
|
|
56
|
-
const result = [];
|
|
57
|
-
Object.values(this._plugins).forEach((value) => {
|
|
58
|
-
result.push(value.schema);
|
|
59
|
-
});
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
validate(payload) {
|
|
63
|
-
var _a, _b;
|
|
64
|
-
return (_b = (_a = this.resolve(payload)).validate) == null ? void 0 : _b.call(_a, payload);
|
|
65
|
-
}
|
|
66
|
-
wrap(payload) {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
return (_b = (_a = this.resolve(payload)).wrap) == null ? void 0 : _b.call(_a, payload);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
export {
|
|
72
|
-
PayloadPluginResolver,
|
|
73
|
-
createPayloadPlugin,
|
|
74
|
-
defaultPayloadPluginFunctions
|
|
75
|
-
};
|
|
76
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/createPlugin.ts","../../src/Resolver.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadValidator } from '@xyo-network/payload-validator'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { PayloadPlugin } from './Plugin'\n\nexport const defaultPayloadPluginFunctions = <T extends Payload>(schema: string): PayloadPlugin<T> => {\n return {\n build: (): PayloadBuilder<T> => {\n return new PayloadBuilder<T>({ schema })\n },\n schema,\n validate: (payload: Payload): PayloadValidator<T> => {\n return new PayloadValidator<T>(payload as T)\n },\n wrap: (payload: Payload): PayloadWrapper<T> => {\n return PayloadWrapper.wrap<T>(payload as T)\n },\n }\n}\n\nexport const createPayloadPlugin = <TPayload extends Payload = Payload>(plugin: PayloadPlugin<TPayload>): PayloadPlugin<TPayload> => {\n return {\n ...defaultPayloadPluginFunctions<TPayload>(assertEx(plugin.schema, 'schema field required to create plugin')),\n ...plugin,\n }\n}\n","import { Validator } from '@xyo-network/core'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { createPayloadPlugin } from './createPlugin'\nimport { PayloadPlugin } from './Plugin'\n\nexport class PayloadPluginResolver {\n schema = PayloadSchema\n\n protected _plugins: Record<string, PayloadPlugin> = {}\n protected defaultPlugin: PayloadPlugin\n\n constructor(\n /** @param plugins The initial set of plugins */\n plugins?: PayloadPlugin<Payload>[],\n /** @param defaultPlugin Specifies the plugin to be used if no plugins resolve */\n defaultPlugin = createPayloadPlugin<Payload>({\n schema: PayloadSchema,\n }),\n ) {\n plugins?.forEach((plugin) => this.register(plugin))\n this.defaultPlugin = defaultPlugin\n }\n\n /** @description Create list of plugins, optionally filtered by ability to witness/divine */\n plugins() {\n const result: PayloadPlugin[] = []\n Object.values(this._plugins).forEach((value) => {\n result.push(value)\n })\n return result\n }\n\n register<TPlugin extends PayloadPlugin = PayloadPlugin>(plugin: TPlugin) {\n this._plugins[plugin.schema] = plugin\n\n return this\n }\n\n resolve(schema?: string): PayloadPlugin\n resolve(payload: Payload): PayloadPlugin\n resolve(value: Payload | string | undefined): PayloadPlugin {\n return value ? this._plugins[typeof value === 'string' ? value : value.schema] ?? this.defaultPlugin : this.defaultPlugin\n }\n\n /** @description Create list of schema, optionally filtered by ability to witness/divine */\n schemas() {\n const result: string[] = []\n Object.values(this._plugins).forEach((value) => {\n result.push(value.schema)\n })\n return result\n }\n\n validate(payload: Payload): Validator<Payload> | undefined {\n return this.resolve(payload).validate?.(payload)\n }\n\n wrap(payload: Payload): PayloadWrapper<Payload> | undefined {\n return this.resolve(payload).wrap?.(payload)\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAE/B,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAIxB,IAAM,gCAAgC,CAAoB,WAAqC;AACpG,SAAO;AAAA,IACL,OAAO,MAAyB;AAC9B,aAAO,IAAI,eAAkB,EAAE,OAAO,CAAC;AAAA,IACzC;AAAA,IACA;AAAA,IACA,UAAU,CAAC,YAA0C;AACnD,aAAO,IAAI,iBAAoB,OAAY;AAAA,IAC7C;AAAA,IACA,MAAM,CAAC,YA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