tachyon-protocol 0.3.0 → 0.3.2

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.
Files changed (52) hide show
  1. package/README.md +33 -111
  2. package/dist/{bot → autohost}/slave/request.json +5 -4
  3. package/dist/{bot/unslave → autohost/slave}/response.json +8 -7
  4. package/dist/{bot → autohost}/unslave/request.json +5 -4
  5. package/dist/autohost/unslave/response.json +107 -0
  6. package/dist/game/launch/response.json +1 -1
  7. package/dist/index.d.ts +1054 -179
  8. package/dist/index.js +147 -25
  9. package/dist/lobby/close/request.json +1 -1
  10. package/dist/lobby/close/response.json +1 -1
  11. package/dist/lobby/create/request.json +1 -1
  12. package/dist/lobby/create/response.json +1 -1
  13. package/dist/lobby/join/request.json +1 -1
  14. package/dist/lobby/join/response.json +1 -1
  15. package/dist/lobby/joined/response.json +327 -110
  16. package/dist/lobby/leave/request.json +1 -1
  17. package/dist/lobby/leave/response.json +1 -1
  18. package/dist/lobby/left/response.json +1 -1
  19. package/dist/lobby/list/request.json +1 -1
  20. package/dist/lobby/list/response.json +475 -119
  21. package/dist/lobby/receiveMessage/response.json +1 -1
  22. package/dist/lobby/sendMessage/request.json +1 -1
  23. package/dist/lobby/sendMessage/response.json +1 -1
  24. package/dist/lobby/subscribe/request.json +33 -0
  25. package/dist/{bot/slave → lobby/subscribe}/response.json +6 -7
  26. package/dist/lobby/unsubscribe/request.json +30 -0
  27. package/dist/lobby/unsubscribe/response.json +131 -0
  28. package/dist/lobby/updated/response.json +459 -143
  29. package/dist/matchmaking/cancel/request.json +1 -1
  30. package/dist/matchmaking/cancel/response.json +1 -1
  31. package/dist/matchmaking/found/response.json +1 -1
  32. package/dist/matchmaking/list/request.json +1 -1
  33. package/dist/matchmaking/list/response.json +13 -7
  34. package/dist/matchmaking/lost/response.json +1 -1
  35. package/dist/matchmaking/queue/request.json +1 -1
  36. package/dist/matchmaking/queue/response.json +1 -1
  37. package/dist/matchmaking/queueUpdate/response.json +1 -1
  38. package/dist/matchmaking/ready/request.json +1 -1
  39. package/dist/matchmaking/ready/response.json +1 -1
  40. package/dist/matchmaking/readyUpdate/response.json +1 -1
  41. package/dist/system/connected/response.json +183 -4
  42. package/dist/system/disconnect/request.json +12 -1
  43. package/dist/system/disconnect/response.json +105 -0
  44. package/dist/system/serverStats/request.json +18 -0
  45. package/dist/system/serverStats/response.json +117 -0
  46. package/dist/user/subscribe/request.json +33 -0
  47. package/dist/user/subscribe/response.json +290 -0
  48. package/dist/user/unsubscribe/request.json +33 -0
  49. package/dist/user/unsubscribe/response.json +131 -0
  50. package/dist/user/updated/response.json +304 -0
  51. package/package.json +18 -6
  52. package/dist/meta.json +0 -96
package/dist/index.js CHANGED
@@ -4291,19 +4291,19 @@ var require_core = __commonJS({
4291
4291
  this.addKeyword("$async");
4292
4292
  }
4293
4293
  _addDefaultMetaSchema() {
4294
- const { $data, meta, schemaId } = this.opts;
4294
+ const { $data, meta: meta2, schemaId } = this.opts;
4295
4295
  let _dataRefSchema = $dataRefSchema;
4296
4296
  if (schemaId === "id") {
4297
4297
  _dataRefSchema = { ...$dataRefSchema };
4298
4298
  _dataRefSchema.id = _dataRefSchema.$id;
4299
4299
  delete _dataRefSchema.$id;
4300
4300
  }
4301
- if (meta && $data)
4301
+ if (meta2 && $data)
4302
4302
  this.addMetaSchema(_dataRefSchema, _dataRefSchema[schemaId], false);
4303
4303
  }
4304
4304
  defaultMeta() {
4305
- const { meta, schemaId } = this.opts;
4306
- return this.opts.defaultMeta = typeof meta == "object" ? meta[schemaId] || meta : void 0;
4305
+ const { meta: meta2, schemaId } = this.opts;
4306
+ return this.opts.defaultMeta = typeof meta2 == "object" ? meta2[schemaId] || meta2 : void 0;
4307
4307
  }
4308
4308
  validate(schemaKeyRef, data) {
4309
4309
  let v;
@@ -4323,12 +4323,12 @@ var require_core = __commonJS({
4323
4323
  const sch = this._addSchema(schema, _meta);
4324
4324
  return sch.validate || this._compileSchemaEnv(sch);
4325
4325
  }
4326
- compileAsync(schema, meta) {
4326
+ compileAsync(schema, meta2) {
4327
4327
  if (typeof this.opts.loadSchema != "function") {
4328
4328
  throw new Error("options.loadSchema should be a function");
4329
4329
  }
4330
4330
  const { loadSchema } = this.opts;
4331
- return runCompileAsync.call(this, schema, meta);
4331
+ return runCompileAsync.call(this, schema, meta2);
4332
4332
  async function runCompileAsync(_schema, _meta) {
4333
4333
  await loadMetaSchema.call(this, _schema.$schema);
4334
4334
  const sch = this._addSchema(_schema, _meta);
@@ -4360,7 +4360,7 @@ var require_core = __commonJS({
4360
4360
  if (!this.refs[ref])
4361
4361
  await loadMetaSchema.call(this, _schema.$schema);
4362
4362
  if (!this.refs[ref])
4363
- this.addSchema(_schema, ref, meta);
4363
+ this.addSchema(_schema, ref, meta2);
4364
4364
  }
4365
4365
  async function _loadSchema(ref) {
4366
4366
  const p = this._loading[ref];
@@ -4577,7 +4577,7 @@ var require_core = __commonJS({
4577
4577
  }
4578
4578
  }
4579
4579
  }
4580
- _addSchema(schema, meta, baseId, validateSchema = this.opts.validateSchema, addSchema = this.opts.addUsedSchema) {
4580
+ _addSchema(schema, meta2, baseId, validateSchema = this.opts.validateSchema, addSchema = this.opts.addUsedSchema) {
4581
4581
  let id;
4582
4582
  const { schemaId } = this.opts;
4583
4583
  if (typeof schema == "object") {
@@ -4593,7 +4593,7 @@ var require_core = __commonJS({
4593
4593
  return sch;
4594
4594
  baseId = (0, resolve_1.normalizeId)(id || baseId);
4595
4595
  const localRefs = resolve_1.getSchemaRefs.call(this, schema, baseId);
4596
- sch = new compile_1.SchemaEnv({ schema, schemaId, meta, baseId, localRefs });
4596
+ sch = new compile_1.SchemaEnv({ schema, schemaId, meta: meta2, baseId, localRefs });
4597
4597
  this._cache.set(sch.schema, sch);
4598
4598
  if (addSchema && !baseId.startsWith("#")) {
4599
4599
  if (baseId)
@@ -7065,33 +7065,155 @@ var require_dist = __commonJS({
7065
7065
  }
7066
7066
  });
7067
7067
 
7068
- // src/validator.ts
7069
- var validator_exports = {};
7070
- __export(validator_exports, {
7068
+ // src/compiled.ts
7069
+ var compiled_exports = {};
7070
+ __export(compiled_exports, {
7071
7071
  getValidator: () => getValidator,
7072
7072
  tachyonMeta: () => tachyonMeta
7073
7073
  });
7074
- module.exports = __toCommonJS(validator_exports);
7074
+ module.exports = __toCommonJS(compiled_exports);
7075
+
7076
+ // src/meta.ts
7077
+ var tachyonMeta = {
7078
+ "version": "0.3.2",
7079
+ "ids": {
7080
+ "autohost": {
7081
+ "slave": [
7082
+ "request",
7083
+ "response"
7084
+ ],
7085
+ "unslave": [
7086
+ "request",
7087
+ "response"
7088
+ ]
7089
+ },
7090
+ "game": {
7091
+ "launch": [
7092
+ "response"
7093
+ ]
7094
+ },
7095
+ "lobby": {
7096
+ "close": [
7097
+ "request",
7098
+ "response"
7099
+ ],
7100
+ "create": [
7101
+ "request",
7102
+ "response"
7103
+ ],
7104
+ "join": [
7105
+ "request",
7106
+ "response"
7107
+ ],
7108
+ "joined": [
7109
+ "response"
7110
+ ],
7111
+ "leave": [
7112
+ "request",
7113
+ "response"
7114
+ ],
7115
+ "left": [
7116
+ "response"
7117
+ ],
7118
+ "list": [
7119
+ "request",
7120
+ "response"
7121
+ ],
7122
+ "receiveMessage": [
7123
+ "response"
7124
+ ],
7125
+ "sendMessage": [
7126
+ "request",
7127
+ "response"
7128
+ ],
7129
+ "subscribe": [
7130
+ "request",
7131
+ "response"
7132
+ ],
7133
+ "unsubscribe": [
7134
+ "request",
7135
+ "response"
7136
+ ],
7137
+ "updated": [
7138
+ "response"
7139
+ ]
7140
+ },
7141
+ "matchmaking": {
7142
+ "cancel": [
7143
+ "request",
7144
+ "response"
7145
+ ],
7146
+ "found": [
7147
+ "response"
7148
+ ],
7149
+ "list": [
7150
+ "request",
7151
+ "response"
7152
+ ],
7153
+ "lost": [
7154
+ "response"
7155
+ ],
7156
+ "queue": [
7157
+ "request",
7158
+ "response"
7159
+ ],
7160
+ "queueUpdate": [
7161
+ "response"
7162
+ ],
7163
+ "ready": [
7164
+ "request",
7165
+ "response"
7166
+ ],
7167
+ "readyUpdate": [
7168
+ "response"
7169
+ ]
7170
+ },
7171
+ "system": {
7172
+ "connected": [
7173
+ "response"
7174
+ ],
7175
+ "disconnect": [
7176
+ "request",
7177
+ "response"
7178
+ ],
7179
+ "serverStats": [
7180
+ "request",
7181
+ "response"
7182
+ ]
7183
+ },
7184
+ "user": {
7185
+ "subscribe": [
7186
+ "request",
7187
+ "response"
7188
+ ],
7189
+ "unsubscribe": [
7190
+ "request",
7191
+ "response"
7192
+ ],
7193
+ "updated": [
7194
+ "response"
7195
+ ]
7196
+ }
7197
+ }
7198
+ };
7199
+
7200
+ // src/validator.ts
7075
7201
  var import_ajv = __toESM(require_ajv());
7076
7202
  var import_ajv_formats = __toESM(require_dist());
7077
7203
  var import_fs = __toESM(require("fs"));
7078
7204
  var import_path = __toESM(require("path"));
7079
- var tachyonMeta = JSON.parse(
7080
- import_fs.default.readFileSync(import_path.default.join(__dirname, `./meta.json`), {
7081
- encoding: "utf-8"
7082
- })
7083
- );
7205
+ var meta = tachyonMeta;
7084
7206
  var validators = /* @__PURE__ */ new Map();
7085
- var ajv = new import_ajv.default({ coerceTypes: true });
7207
+ var ajv = new import_ajv.default();
7086
7208
  var initialised = false;
7087
7209
  function init() {
7088
7210
  initialised = true;
7089
7211
  import_ajv_formats.default.default(ajv);
7090
7212
  ajv.addKeyword("requiresLogin");
7091
7213
  ajv.addKeyword("requiresRole");
7092
- for (const serviceId in tachyonMeta.ids) {
7093
- for (const endpointId in tachyonMeta.ids[serviceId]) {
7094
- for (const commandType of tachyonMeta.ids[serviceId][endpointId]) {
7214
+ for (const serviceId in meta.ids) {
7215
+ for (const endpointId in meta.ids[serviceId]) {
7216
+ for (const commandType of meta.ids[serviceId][endpointId]) {
7095
7217
  const commandId = `${serviceId}/${endpointId}/${commandType}`;
7096
7218
  const commandSchemaStr = import_fs.default.readFileSync(
7097
7219
  import_path.default.join(__dirname, `./${serviceId}/${endpointId}/${commandType}.json`),
@@ -7111,12 +7233,12 @@ function getValidator(command) {
7111
7233
  if (typeof command !== "object") {
7112
7234
  throw new Error("Command not object type");
7113
7235
  }
7114
- if (!command.command || typeof command.command !== "string") {
7236
+ if (!command.commandId || typeof command.commandId !== "string") {
7115
7237
  throw new Error("Command Id missing");
7116
7238
  }
7117
- const validator = validators.get(command.command);
7239
+ const validator = validators.get(command.commandId);
7118
7240
  if (!validator) {
7119
- throw new Error(`Validator not found for: ${command.command}`);
7241
+ throw new Error(`Validator not found for: ${command.commandId}`);
7120
7242
  }
7121
7243
  return validator;
7122
7244
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$id": "lobby/close/request",
3
- "requiresLogin": false,
3
+ "roles": [],
4
4
  "type": "object",
5
5
  "properties": {
6
6
  "messageId": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$id": "lobby/close/response",
3
- "requiresLogin": false,
3
+ "roles": [],
4
4
  "anyOf": [
5
5
  {
6
6
  "type": "object",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$id": "lobby/create/request",
3
- "requiresLogin": false,
3
+ "roles": [],
4
4
  "type": "object",
5
5
  "properties": {
6
6
  "messageId": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$id": "lobby/create/response",
3
- "requiresLogin": false,
3
+ "roles": [],
4
4
  "anyOf": [
5
5
  {
6
6
  "type": "object",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$id": "lobby/join/request",
3
- "requiresLogin": false,
3
+ "roles": [],
4
4
  "type": "object",
5
5
  "properties": {
6
6
  "messageId": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$id": "lobby/join/response",
3
- "requiresLogin": false,
3
+ "roles": [],
4
4
  "anyOf": [
5
5
  {
6
6
  "type": "object",