tachyon-protocol 1.0.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 CHANGED
@@ -1,8 +1,8 @@
1
1
  import { EmptyObject, KeysOfUnion } from 'type-fest';
2
- import { ValidateFunction } from 'ajv';
2
+ import Ajv from 'ajv';
3
3
 
4
4
  declare const tachyonMeta: {
5
- readonly version: "1.0.0";
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
@@ -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, fs2, exportName) {
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, fs2[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.0.0",
7064
+ "version": "1.2.0",
7065
7065
  "ids": {
7066
7066
  "autohost": {
7067
7067
  "slave": [
@@ -7186,16 +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 fs from "node:fs";
7190
7189
  import path, { dirname } from "node:path";
7191
- import { fileURLToPath } from "url";
7192
- var __filename = fileURLToPath(import.meta.url);
7193
- var __dirname = dirname(__filename);
7194
7190
  var meta = tachyonMeta;
7195
7191
  var validators = /* @__PURE__ */ new Map();
7196
7192
  var ajv = new import_ajv.default.default();
7197
7193
  var initialised = false;
7198
- function init() {
7194
+ async function init() {
7199
7195
  initialised = true;
7200
7196
  import_ajv_formats.default.default(ajv);
7201
7197
  ajv.addKeyword("roles");
@@ -7203,20 +7199,20 @@ function init() {
7203
7199
  for (const endpointId in meta.ids[serviceId]) {
7204
7200
  for (const commandType of meta.ids[serviceId][endpointId]) {
7205
7201
  const commandId = `${serviceId}/${endpointId}/${commandType}`;
7206
- const commandSchemaStr = fs.readFileSync(
7207
- path.join(__dirname, `./${serviceId}/${endpointId}/${commandType}.json`),
7208
- { encoding: "utf-8" }
7202
+ const jsonSchemaPath = new URL(
7203
+ `${serviceId}/${endpointId}/${commandType}.json`,
7204
+ path.join(dirname(import.meta.url), "dist")
7209
7205
  );
7210
- const commandSchema = JSON.parse(commandSchemaStr);
7206
+ const commandSchema = await import(jsonSchemaPath.href);
7211
7207
  const validator = ajv.compile(commandSchema);
7212
7208
  validators.set(commandId, validator);
7213
7209
  }
7214
7210
  }
7215
7211
  }
7216
7212
  }
7217
- function getValidator(command) {
7213
+ async function getValidator(command) {
7218
7214
  if (!initialised) {
7219
- init();
7215
+ await init();
7220
7216
  }
7221
7217
  if (typeof command !== "object") {
7222
7218
  throw new Error("Command not object type");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tachyon-protocol",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {