@arcote.tech/arc-host 0.1.7 → 0.1.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../host.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,aAAa,EAElB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EAGvB,KAAK,4BAA4B,EAClC,MAAM,kBAAkB,CAAC;AAI1B,cAAM,OAAQ,YAAW,4BAA4B;IAMjD,OAAO,CAAC,OAAO;IALjB,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,KAAK,CAAuB;gBAG1B,OAAO,EAAE,aAAa,EAC9B,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC;IASrC,aAAa,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,IAAI;IAI5C,IAAI,CACR,gBAAgB,EAAE,CAAC,EACjB,KAAK,EACL,IAAI,GACL,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,IAAI,GACT,OAAO,CAAC,IAAI,CAAC;YAIF,eAAe;IAS7B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAW1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAuB1B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAQ7B;;OAEG;YACW,qBAAqB;IAWnC;;OAEG;IACH,OAAO,CAAC,iBAAiB;YAwCX,aAAa;YAoDb,WAAW;YAiEX,WAAW;IAgEzB,OAAO,CAAC,WAAW;IAmEnB,OAAO,CAAC,gBAAgB;YA4BV,UAAU;YA+CV,SAAS;IAevB,OAAO,CAAC,cAAc;CAGvB;AAED,eAAO,MAAM,cAAc,YACf,aAAa,aAAa,OAAO,CAAC,eAAe,CAAC,kBAE3D,CAAC"}
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../host.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,aAAa,EAElB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EAGvB,KAAK,4BAA4B,EAClC,MAAM,kBAAkB,CAAC;AAI1B,cAAM,OAAQ,YAAW,4BAA4B;IAMjD,OAAO,CAAC,OAAO;IALjB,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,KAAK,CAAuB;gBAG1B,OAAO,EAAE,aAAa,EAC9B,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC;IASrC,aAAa,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,IAAI;IAI5C,IAAI,CACR,gBAAgB,EAAE,CAAC,EACjB,KAAK,EACL,IAAI,GACL,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,IAAI,GACT,OAAO,CAAC,IAAI,CAAC;YAIF,eAAe;IAS7B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAuB1B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAM7B;;OAEG;YACW,qBAAqB;IAWnC;;OAEG;IACH,OAAO,CAAC,iBAAiB;YAwCX,aAAa;YAoDb,WAAW;YAiEX,WAAW;IAgEzB,OAAO,CAAC,WAAW;IAoEnB,OAAO,CAAC,gBAAgB;YA4BV,UAAU;YA+CV,SAAS;IAevB,OAAO,CAAC,cAAc;CAGvB;AAED,eAAO,MAAM,cAAc,YACf,aAAa,aAAa,OAAO,CAAC,eAAe,CAAC,kBAE3D,CAAC"}
package/dist/index.js CHANGED
@@ -5019,9 +5019,15 @@ class ArcDefault {
5019
5019
 
5020
5020
  class ArcAbstract {
5021
5021
  validations;
5022
+ _description;
5022
5023
  constructor(validations = []) {
5023
5024
  this.validations = validations;
5024
5025
  }
5026
+ description(description) {
5027
+ const clone = this.clone();
5028
+ clone._description = description;
5029
+ return clone;
5030
+ }
5025
5031
  default(defaultValueOrCallback) {
5026
5032
  return new ArcDefault(this, defaultValueOrCallback);
5027
5033
  }
@@ -5034,6 +5040,7 @@ class ArcAbstract {
5034
5040
  clone() {
5035
5041
  const Constructor = this.constructor;
5036
5042
  const newInstance = Object.assign(new Constructor, this);
5043
+ newInstance._description = this._description;
5037
5044
  return newInstance;
5038
5045
  }
5039
5046
  validate(value) {
@@ -5056,7 +5063,11 @@ class ArcAbstract {
5056
5063
  return newInstance;
5057
5064
  }
5058
5065
  toJsonSchema() {
5059
- return {};
5066
+ const schema = {};
5067
+ if (this._description) {
5068
+ schema.description = this._description;
5069
+ }
5070
+ return schema;
5060
5071
  }
5061
5072
  getValidations() {
5062
5073
  return this.validations;
@@ -5174,7 +5185,11 @@ class ArcString extends ArcPrimitive {
5174
5185
  });
5175
5186
  }
5176
5187
  toJsonSchema() {
5177
- return { type: "string" };
5188
+ const schema = { type: "string" };
5189
+ if (this._description) {
5190
+ schema.description = this._description;
5191
+ }
5192
+ return schema;
5178
5193
  }
5179
5194
  url() {
5180
5195
  const regex = /^(https?):\/\/(?![-0-9])(?!www\.[0-9])(?:[a-zA-Z0-9-]+(?::[a-zA-Z0-9-]+)?@)?(?:localhost|\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b|[a-zA-Z0-9-]+\.)?[a-zA-Z0-9-]+\.(?:[a-zA-Z]{2,}|[a-zA-Z]{2}\.[a-zA-Z]{2})(?::\d{1,5})?(?!\/\/)(?:\/[a-zA-Z0-9-._~:?#\[\]@!$&'()*+,;=]*)*(?!\/{2})(?:;[a-zA-Z0-9-._~:?#\[\]@!$&'()*+,;=]*)*(\?(?!=)[a-zA-Z0-9&=;]*)?(\#[a-zA-Z0-9-]*)?$|^(https?):\/\/(localhost|\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b)(?::\d{1,5})?(?!\/\/)(?:\/[a-zA-Z0-9-._~:?#\[\]@!$&'()*+,;=]*)*(?!\/{2})(?:;[a-zA-Z0-9-._~:?#\[\]@!$&'()*+,;=]*)*(\?(?!=)[a-zA-Z0-9&=;]*)?(\#[a-zA-Z0-9-]*)?$/;
@@ -5218,18 +5233,23 @@ class ArcCustomId extends ArcBranded {
5218
5233
  }
5219
5234
 
5220
5235
  class ArcId extends ArcBranded {
5221
- constructor(name) {
5236
+ generateFn;
5237
+ constructor(name, generateFn) {
5222
5238
  super(string(), name);
5239
+ this.generateFn = generateFn;
5223
5240
  }
5224
5241
  generate() {
5242
+ if (this.generateFn) {
5243
+ return this.generateFn();
5244
+ }
5225
5245
  var timestamp = (new Date().getTime() / 1000 | 0).toString(16);
5226
5246
  return timestamp + "xxxxxxxxxxxxxxxx".replace(/[x]/g, function() {
5227
5247
  return (Math.random() * 16 | 0).toString(16);
5228
5248
  }).toLowerCase();
5229
5249
  }
5230
5250
  }
5231
- function id(name) {
5232
- return new ArcId(name);
5251
+ function id(name, generateFn) {
5252
+ return new ArcId(name, generateFn);
5233
5253
  }
5234
5254
  var objectValidator = typeValidatorBuilder("object");
5235
5255
 
@@ -5308,6 +5328,10 @@ class ArcObject extends ArcAbstract {
5308
5328
  }
5309
5329
  serializePartial(value) {
5310
5330
  return Object.entries(value).reduce((acc, [key, value2]) => {
5331
+ if (!this.rawShape[key]) {
5332
+ console.warn(`No element found for key: ${key}`);
5333
+ return acc;
5334
+ }
5311
5335
  acc[key] = this.rawShape[key].serialize(value2);
5312
5336
  return acc;
5313
5337
  }, {});
@@ -5352,6 +5376,9 @@ class ArcObject extends ArcAbstract {
5352
5376
  };
5353
5377
  if (required.length)
5354
5378
  schema.required = required;
5379
+ if (this._description) {
5380
+ schema.description = this._description;
5381
+ }
5355
5382
  return schema;
5356
5383
  }
5357
5384
  }
@@ -5439,10 +5466,14 @@ class ArcArray extends ArcAbstract {
5439
5466
  return instance;
5440
5467
  }
5441
5468
  toJsonSchema() {
5442
- return {
5469
+ const schema = {
5443
5470
  type: "array",
5444
5471
  items: this.parent.toJsonSchema?.() ?? {}
5445
5472
  };
5473
+ if (this._description) {
5474
+ schema.description = this._description;
5475
+ }
5476
+ return schema;
5446
5477
  }
5447
5478
  }
5448
5479
  class ArcBoolean extends ArcPrimitive {
@@ -5459,7 +5490,11 @@ class ArcBoolean extends ArcPrimitive {
5459
5490
  return instance;
5460
5491
  }
5461
5492
  toJsonSchema() {
5462
- return { type: "boolean" };
5493
+ const schema = { type: "boolean" };
5494
+ if (this._description) {
5495
+ schema.description = this._description;
5496
+ }
5497
+ return schema;
5463
5498
  }
5464
5499
  }
5465
5500
  var dateValidator = typeValidatorBuilder("Date", (value) => value instanceof Date);
@@ -5497,10 +5532,14 @@ class ArcDate extends ArcAbstract {
5497
5532
  return instance;
5498
5533
  }
5499
5534
  toJsonSchema() {
5500
- return {
5535
+ const schema = {
5501
5536
  type: "string",
5502
5537
  format: "date-time"
5503
5538
  };
5539
+ if (this._description) {
5540
+ schema.description = this._description;
5541
+ }
5542
+ return schema;
5504
5543
  }
5505
5544
  }
5506
5545
  var numberValidator = typeValidatorBuilder("number");
@@ -5526,7 +5565,11 @@ class ArcNumber extends ArcPrimitive {
5526
5565
  return instance;
5527
5566
  }
5528
5567
  toJsonSchema() {
5529
- return { type: "number" };
5568
+ const schema = { type: "number" };
5569
+ if (this._description) {
5570
+ schema.description = this._description;
5571
+ }
5572
+ return schema;
5530
5573
  }
5531
5574
  }
5532
5575
  function getSQLiteType(element2) {
@@ -6823,7 +6866,6 @@ class RTCHost {
6823
6866
  tokenToAuthContext(payload, ipAddress) {
6824
6867
  return {
6825
6868
  userId: payload.userId,
6826
- roles: [],
6827
6869
  ipAddress
6828
6870
  };
6829
6871
  }
@@ -6844,8 +6886,6 @@ class RTCHost {
6844
6886
  }
6845
6887
  getDefaultAuthContext(ipAddress) {
6846
6888
  return {
6847
- userId: undefined,
6848
- roles: [],
6849
6889
  ipAddress
6850
6890
  };
6851
6891
  }
@@ -7061,7 +7101,8 @@ class RTCHost {
7061
7101
  perMessageDeflate: true,
7062
7102
  backpressureLimit: 16 * 1024 * 1024
7063
7103
  },
7064
- port: 5005
7104
+ port: 5005,
7105
+ idleTimeout: 30
7065
7106
  });
7066
7107
  }
7067
7108
  isPublicEndpoint(pathname) {
package/host.ts CHANGED
@@ -66,9 +66,8 @@ class RTCHost implements RealTimeCommunicationAdapter {
66
66
  ): AuthContext {
67
67
  return {
68
68
  userId: payload.userId,
69
- roles: [], // Default to no roles, you may want to extend TokenPayload to include roles
70
69
  ipAddress,
71
- };
70
+ } as AuthContext;
72
71
  }
73
72
 
74
73
  /**
@@ -102,8 +101,6 @@ class RTCHost implements RealTimeCommunicationAdapter {
102
101
  */
103
102
  private getDefaultAuthContext(ipAddress?: string): AuthContext {
104
103
  return {
105
- userId: undefined as any,
106
- roles: [],
107
104
  ipAddress,
108
105
  };
109
106
  }
@@ -410,6 +407,7 @@ class RTCHost implements RealTimeCommunicationAdapter {
410
407
  backpressureLimit: 16 * 1024 * 1024,
411
408
  },
412
409
  port: 5005,
410
+ idleTimeout: 30,
413
411
  });
414
412
  }
415
413
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
7
- "version": "0.1.7",
7
+ "version": "0.1.9",
8
8
  "private": false,
9
9
  "author": "Przemysław Krasiński [arcote.tech]",
10
10
  "dependencies": {