tachyon-protocol 1.1.0 → 1.2.0
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/index.d.ts +3 -3
- package/dist/index.js +14 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EmptyObject, KeysOfUnion } from 'type-fest';
|
|
2
|
-
import
|
|
2
|
+
import Ajv from 'ajv';
|
|
3
3
|
|
|
4
4
|
declare const tachyonMeta: {
|
|
5
|
-
readonly version: "1.
|
|
5
|
+
readonly version: "1.2.0";
|
|
6
6
|
readonly ids: {
|
|
7
7
|
readonly autohost: {
|
|
8
8
|
readonly slave: readonly ["request", "response"];
|
|
@@ -119,7 +119,7 @@ type GenericResponseCommand = {
|
|
|
119
119
|
|
|
120
120
|
declare function getValidator<T extends {
|
|
121
121
|
commandId: string;
|
|
122
|
-
}>(command: T): ValidateFunction<T
|
|
122
|
+
}>(command: T): Promise<Ajv.ValidateFunction<T>>;
|
|
123
123
|
|
|
124
124
|
export { Command, DataRequestId, EmptyRequestId, EndpointId, GenericRequestCommand, GenericResponseCommand, RequestCommand, RequestCommandId, RequestData, RequestEndpointId, RequestType, ResponseCommand, ResponseCommandId, ResponseData, ResponseEndpointId, ResponseOnlyEndpointId, ResponseType, ServiceId, SuccessResponseData, getValidator, tachyonMeta };
|
|
125
125
|
|
package/dist/index.js
CHANGED
|
@@ -3935,8 +3935,8 @@ var require_uri_all = __commonJS({
|
|
|
3935
3935
|
wsComponents.secure = void 0;
|
|
3936
3936
|
}
|
|
3937
3937
|
if (wsComponents.resourceName) {
|
|
3938
|
-
var _wsComponents$resourc = wsComponents.resourceName.split("?"), _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2),
|
|
3939
|
-
wsComponents.path =
|
|
3938
|
+
var _wsComponents$resourc = wsComponents.resourceName.split("?"), _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2), path2 = _wsComponents$resourc2[0], query = _wsComponents$resourc2[1];
|
|
3939
|
+
wsComponents.path = path2 && path2 !== "/" ? path2 : void 0;
|
|
3940
3940
|
wsComponents.query = query;
|
|
3941
3941
|
wsComponents.resourceName = void 0;
|
|
3942
3942
|
}
|
|
@@ -7046,12 +7046,12 @@ var require_dist = __commonJS({
|
|
|
7046
7046
|
throw new Error(`Unknown format "${name}"`);
|
|
7047
7047
|
return f;
|
|
7048
7048
|
};
|
|
7049
|
-
function addFormats2(ajv2, list,
|
|
7049
|
+
function addFormats2(ajv2, list, fs, exportName) {
|
|
7050
7050
|
var _a;
|
|
7051
7051
|
var _b;
|
|
7052
7052
|
(_a = (_b = ajv2.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = codegen_1._`require("ajv-formats/dist/formats").${exportName}`;
|
|
7053
7053
|
for (const f of list)
|
|
7054
|
-
ajv2.addFormat(f,
|
|
7054
|
+
ajv2.addFormat(f, fs[f]);
|
|
7055
7055
|
}
|
|
7056
7056
|
module.exports = exports = formatsPlugin;
|
|
7057
7057
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -7061,7 +7061,7 @@ var require_dist = __commonJS({
|
|
|
7061
7061
|
|
|
7062
7062
|
// src/meta.ts
|
|
7063
7063
|
var tachyonMeta = {
|
|
7064
|
-
"version": "1.
|
|
7064
|
+
"version": "1.2.0",
|
|
7065
7065
|
"ids": {
|
|
7066
7066
|
"autohost": {
|
|
7067
7067
|
"slave": [
|
|
@@ -7186,12 +7186,12 @@ var tachyonMeta = {
|
|
|
7186
7186
|
// src/validator.ts
|
|
7187
7187
|
var import_ajv = __toESM(require_ajv(), 1);
|
|
7188
7188
|
var import_ajv_formats = __toESM(require_dist(), 1);
|
|
7189
|
-
import
|
|
7189
|
+
import path, { dirname } from "node:path";
|
|
7190
7190
|
var meta = tachyonMeta;
|
|
7191
7191
|
var validators = /* @__PURE__ */ new Map();
|
|
7192
7192
|
var ajv = new import_ajv.default.default();
|
|
7193
7193
|
var initialised = false;
|
|
7194
|
-
function init() {
|
|
7194
|
+
async function init() {
|
|
7195
7195
|
initialised = true;
|
|
7196
7196
|
import_ajv_formats.default.default(ajv);
|
|
7197
7197
|
ajv.addKeyword("roles");
|
|
@@ -7199,18 +7199,20 @@ function init() {
|
|
|
7199
7199
|
for (const endpointId in meta.ids[serviceId]) {
|
|
7200
7200
|
for (const commandType of meta.ids[serviceId][endpointId]) {
|
|
7201
7201
|
const commandId = `${serviceId}/${endpointId}/${commandType}`;
|
|
7202
|
-
const jsonSchemaPath = new URL(
|
|
7203
|
-
|
|
7204
|
-
|
|
7202
|
+
const jsonSchemaPath = new URL(
|
|
7203
|
+
`${serviceId}/${endpointId}/${commandType}.json`,
|
|
7204
|
+
path.join(dirname(import.meta.url), "dist")
|
|
7205
|
+
);
|
|
7206
|
+
const commandSchema = await import(jsonSchemaPath.href);
|
|
7205
7207
|
const validator = ajv.compile(commandSchema);
|
|
7206
7208
|
validators.set(commandId, validator);
|
|
7207
7209
|
}
|
|
7208
7210
|
}
|
|
7209
7211
|
}
|
|
7210
7212
|
}
|
|
7211
|
-
function getValidator(command) {
|
|
7213
|
+
async function getValidator(command) {
|
|
7212
7214
|
if (!initialised) {
|
|
7213
|
-
init();
|
|
7215
|
+
await init();
|
|
7214
7216
|
}
|
|
7215
7217
|
if (typeof command !== "object") {
|
|
7216
7218
|
throw new Error("Command not object type");
|