@opra/common 0.27.2 → 0.28.1

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/browser.js CHANGED
@@ -367,8 +367,6 @@ var ResponsiveMap = class extends Map {
367
367
 
368
368
  // ../../build/common/esm/i18n/i18n.js
369
369
  import { splitString, tokenize } from "fast-tokenizer";
370
- import fs from "@browsery/fs";
371
- import path from "path-browserify";
372
370
  import i18next from "@browsery/i18next";
373
371
 
374
372
  // ../../build/common/esm/i18n/string-utils.js
@@ -384,8 +382,7 @@ function unescapeString(s) {
384
382
  __name(unescapeString, "unescapeString");
385
383
 
386
384
  // ../../build/common/esm/i18n/i18n.js
387
- var BaseI18n = Object.getPrototypeOf(i18next).constructor;
388
- var globalLocaleDirs = [];
385
+ var BaseI18n = Object.getPrototypeOf(i18next.createInstance()).constructor;
389
386
  var I18n = class _I18n extends BaseI18n {
390
387
  static {
391
388
  __name(this, "I18n");
@@ -399,11 +396,6 @@ var I18n = class _I18n extends BaseI18n {
399
396
  formatter.add("lowercase", (value, lng) => value.toLocaleLowerCase(lng));
400
397
  formatter.add("uppercase", (value, lng) => value.toLocaleUpperCase(lng));
401
398
  formatter.add("upperFirst", (value, lng) => value.charAt(0).toLocaleUpperCase(lng) + value.substring(1));
402
- if (globalLocaleDirs.length)
403
- await this.loadResourceDir(globalLocaleDirs, false, true);
404
- if (options?.resourceDirs?.length) {
405
- await this.loadResourceDir(options.resourceDirs, false, true);
406
- }
407
399
  if (options?.resources) {
408
400
  for (const lang of Object.keys(options.resources)) {
409
401
  const langObj = options.resources[lang];
@@ -427,40 +419,6 @@ var I18n = class _I18n extends BaseI18n {
427
419
  const objectStack = /* @__PURE__ */ new WeakMap();
428
420
  return this._deepTranslate(input, objectStack, options);
429
421
  }
430
- registerLocaleDir(...dirname) {
431
- globalLocaleDirs.push(...dirname);
432
- }
433
- async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
434
- let obj;
435
- if (isUrlString(filePath)) {
436
- obj = (await fetch(filePath, { headers: { accept: "application/json" } })).json();
437
- } else {
438
- const content = fs.readFileSync(filePath, "utf8");
439
- obj = JSON.parse(content);
440
- }
441
- this.addResourceBundle(lang, ns, obj, deep, overwrite);
442
- }
443
- async loadResourceDir(dirnames, deep, overwrite) {
444
- for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
445
- if (!fs.existsSync(dirname))
446
- continue;
447
- const languageDirs = fs.readdirSync(dirname);
448
- for (const lang of languageDirs) {
449
- const langDir = path.join(dirname, lang);
450
- if (fs.statSync(langDir).isDirectory()) {
451
- const nsDirs = fs.readdirSync(langDir);
452
- for (const nsfile of nsDirs) {
453
- const nsFilePath = path.join(langDir, nsfile);
454
- const ext = path.extname(nsfile);
455
- if (ext === ".json" && fs.statSync(nsFilePath).isFile()) {
456
- const ns = path.basename(nsfile, ext);
457
- await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
458
- }
459
- }
460
- }
461
- }
462
- }
463
- }
464
422
  createInstance(options = {}, callback) {
465
423
  return new _I18n(options, callback);
466
424
  }
@@ -1251,10 +1209,10 @@ var ContainerClass = class _ContainerClass extends Resource {
1251
1209
  }
1252
1210
  return schema;
1253
1211
  }
1254
- getResource(path2, silent) {
1212
+ getResource(path, silent) {
1255
1213
  let resource;
1256
- if (path2.includes("/")) {
1257
- const arr = path2.split("/");
1214
+ if (path.includes("/")) {
1215
+ const arr = path.split("/");
1258
1216
  let i;
1259
1217
  const l = arr.length;
1260
1218
  let container = this;
@@ -1268,37 +1226,37 @@ var ContainerClass = class _ContainerClass extends Resource {
1268
1226
  if (!resource || i < l - 1)
1269
1227
  resource = void 0;
1270
1228
  } else
1271
- resource = this.resources.get(path2);
1229
+ resource = this.resources.get(path);
1272
1230
  if (resource || silent)
1273
1231
  return resource;
1274
- throw new ResourceNotFoundError(path2);
1232
+ throw new ResourceNotFoundError(path);
1275
1233
  }
1276
- getContainer(path2, silent) {
1277
- const t = this.getResource(path2);
1234
+ getContainer(path, silent) {
1235
+ const t = this.getResource(path);
1278
1236
  if (!t && silent)
1279
1237
  return;
1280
1238
  if (t && t.kind === opra_schema_ns_exports.Container.Kind)
1281
1239
  return t;
1282
1240
  throw new NotAcceptableError(`Resource type "${t.name}" is not a Container`);
1283
1241
  }
1284
- getCollection(path2, silent) {
1285
- const t = this.getResource(path2);
1242
+ getCollection(path, silent) {
1243
+ const t = this.getResource(path);
1286
1244
  if (!t && silent)
1287
1245
  return;
1288
1246
  if (t && t.kind === opra_schema_ns_exports.Collection.Kind)
1289
1247
  return t;
1290
1248
  throw new NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
1291
1249
  }
1292
- getSingleton(path2, silent) {
1293
- const t = this.getResource(path2);
1250
+ getSingleton(path, silent) {
1251
+ const t = this.getResource(path);
1294
1252
  if (!t && silent)
1295
1253
  return;
1296
1254
  if (t && t.kind === opra_schema_ns_exports.Singleton.Kind)
1297
1255
  return t;
1298
1256
  throw new NotAcceptableError(`Resource type "${t.name}" is not a Singleton`);
1299
1257
  }
1300
- getStorage(path2, silent) {
1301
- const t = this.getResource(path2);
1258
+ getStorage(path, silent) {
1259
+ const t = this.getResource(path);
1302
1260
  if (!t && silent)
1303
1261
  return;
1304
1262
  if (t && t.kind === opra_schema_ns_exports.Storage.Kind)
@@ -1443,6 +1401,8 @@ var FieldClass = class {
1443
1401
  this.default = init.default;
1444
1402
  this.fixed = init.fixed;
1445
1403
  this.required = init.required;
1404
+ this.readonly = init.readonly;
1405
+ this.writeonly = init.writeonly;
1446
1406
  this.exclusive = init.exclusive;
1447
1407
  this.deprecated = init.deprecated;
1448
1408
  this.examples = init.examples;
@@ -1455,22 +1415,18 @@ var FieldClass = class {
1455
1415
  default: this.default,
1456
1416
  fixed: this.fixed,
1457
1417
  required: this.required,
1418
+ readonly: this.readonly,
1419
+ writeonly: this.writeonly,
1458
1420
  exclusive: this.exclusive,
1459
1421
  deprecated: this.deprecated,
1460
1422
  examples: this.examples
1461
1423
  });
1462
1424
  }
1463
- getDecoder() {
1464
- if (!this._decoder)
1465
- this._decoder = this.generateCodec("decode");
1466
- return this._decoder;
1467
- }
1468
- getEncoder() {
1469
- if (!this._encoder)
1470
- this._encoder = this.generateCodec("encode");
1471
- return this._encoder;
1472
- }
1473
1425
  generateCodec(codec, options) {
1426
+ if (options?.operation === "read" && this.writeonly)
1427
+ return vg3.isUndefined();
1428
+ if (options?.operation === "write" && this.readonly)
1429
+ return vg3.isUndefined();
1474
1430
  let fn = this.type.generateCodec(codec, options);
1475
1431
  if (this.isArray)
1476
1432
  fn = vg3.isArray(fn);
@@ -1579,8 +1535,8 @@ var ComplexTypeClass = class extends DataType {
1579
1535
  throw new Error(translate("error:UNKNOWN_FIELD", { field: nameOrPath }));
1580
1536
  return field;
1581
1537
  }
1582
- iteratePath(path2, silent) {
1583
- const arr = path2.split(".");
1538
+ iteratePath(path, silent) {
1539
+ const arr = path.split(".");
1584
1540
  const len = arr.length;
1585
1541
  let dataType = this;
1586
1542
  let field;
@@ -1990,20 +1946,20 @@ var ApiDocument = class extends TypeDocument {
1990
1946
  super(...arguments);
1991
1947
  this.root = new Container2(this, { name: "" });
1992
1948
  }
1993
- getResource(path2, silent) {
1994
- return this.root.getResource(path2, silent);
1949
+ getResource(path, silent) {
1950
+ return this.root.getResource(path, silent);
1995
1951
  }
1996
- getContainer(path2, silent) {
1997
- return this.root.getContainer(path2, silent);
1952
+ getContainer(path, silent) {
1953
+ return this.root.getContainer(path, silent);
1998
1954
  }
1999
- getCollection(path2, silent) {
2000
- return this.root.getCollection(path2, silent);
1955
+ getCollection(path, silent) {
1956
+ return this.root.getCollection(path, silent);
2001
1957
  }
2002
- getSingleton(path2, silent) {
2003
- return this.root.getSingleton(path2, silent);
1958
+ getSingleton(path, silent) {
1959
+ return this.root.getSingleton(path, silent);
2004
1960
  }
2005
- getStorage(path2, silent) {
2006
- return this.root.getStorage(path2, silent);
1961
+ getStorage(path, silent) {
1962
+ return this.root.getStorage(path, silent);
2007
1963
  }
2008
1964
  /**
2009
1965
  * Export as Opra schema definition object
@@ -10378,7 +10334,7 @@ var Operation = class extends Endpoint {
10378
10334
  this.decodeInput = vg7.isAny();
10379
10335
  this.encodeReturning = vg7.isAny();
10380
10336
  this.returnType = init.returnType instanceof DataType ? init.returnType : this.resource.document.getDataType(init.returnType || "any");
10381
- this.encodeReturning = this.returnType.generateCodec("encode");
10337
+ this.encodeReturning = this.returnType.generateCodec("encode", { operation: "read" });
10382
10338
  }
10383
10339
  };
10384
10340
 
@@ -10436,13 +10392,15 @@ var CollectionClass = class extends CrudResource {
10436
10392
  endpoint.decodeInput = this.type.generateCodec("decode", {
10437
10393
  partial: true,
10438
10394
  pick: endpoint.inputPickFields,
10439
- omit: endpoint.inputOmitFields
10395
+ omit: endpoint.inputOmitFields,
10396
+ operation: "write"
10440
10397
  });
10441
10398
  endpoint.returnType = this.type;
10442
10399
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10443
10400
  partial: true,
10444
10401
  pick: endpoint.outputPickFields,
10445
- omit: endpoint.outputOmitFields
10402
+ omit: endpoint.outputOmitFields,
10403
+ operation: "read"
10446
10404
  });
10447
10405
  }
10448
10406
  endpoint = this.operations.get("deleteMany");
@@ -10458,7 +10416,8 @@ var CollectionClass = class extends CrudResource {
10458
10416
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10459
10417
  partial: true,
10460
10418
  pick: endpoint.outputPickFields,
10461
- omit: endpoint.outputOmitFields
10419
+ omit: endpoint.outputOmitFields,
10420
+ operation: "read"
10462
10421
  });
10463
10422
  }
10464
10423
  endpoint = this.operations.get("findMany");
@@ -10476,7 +10435,8 @@ var CollectionClass = class extends CrudResource {
10476
10435
  endpoint.encodeReturning = vg8.isArray(this.type.generateCodec("encode", {
10477
10436
  partial: true,
10478
10437
  pick: endpoint.outputPickFields,
10479
- omit: endpoint.outputOmitFields
10438
+ omit: endpoint.outputOmitFields,
10439
+ operation: "read"
10480
10440
  }));
10481
10441
  }
10482
10442
  endpoint = this.operations.get("update");
@@ -10486,13 +10446,15 @@ var CollectionClass = class extends CrudResource {
10486
10446
  endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10487
10447
  endpoint.decodeInput = this.type.generateCodec("decode", {
10488
10448
  pick: endpoint.inputPickFields,
10489
- omit: endpoint.inputOmitFields
10449
+ omit: endpoint.inputOmitFields,
10450
+ operation: "write"
10490
10451
  });
10491
10452
  endpoint.returnType = this.type;
10492
10453
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10493
10454
  partial: true,
10494
10455
  pick: endpoint.outputPickFields,
10495
- omit: endpoint.outputOmitFields
10456
+ omit: endpoint.outputOmitFields,
10457
+ operation: "read"
10496
10458
  });
10497
10459
  }
10498
10460
  endpoint = this.operations.get("updateMany");
@@ -10500,7 +10462,8 @@ var CollectionClass = class extends CrudResource {
10500
10462
  endpoint.defineParameter("filter", { type: "string", isBuiltin: true });
10501
10463
  endpoint.decodeInput = this.type.generateCodec("decode", {
10502
10464
  pick: endpoint.inputPickFields,
10503
- omit: endpoint.inputOmitFields
10465
+ omit: endpoint.inputOmitFields,
10466
+ operation: "write"
10504
10467
  });
10505
10468
  }
10506
10469
  }
@@ -10545,8 +10508,8 @@ var CollectionClass = class extends CrudResource {
10545
10508
  return result;
10546
10509
  }
10547
10510
  }
10548
- normalizeFieldPath(path2) {
10549
- return this.type.normalizeFieldPath(path2);
10511
+ normalizeFieldPath(path) {
10512
+ return this.type.normalizeFieldPath(path);
10550
10513
  }
10551
10514
  normalizeSortFields(fields) {
10552
10515
  const normalized = this.type.normalizeFieldPath(fields);
@@ -10842,13 +10805,15 @@ var SingletonClass = class extends CrudResource {
10842
10805
  endpoint.decodeInput = this.type.generateCodec("decode", {
10843
10806
  partial: true,
10844
10807
  pick: endpoint.inputPickFields,
10845
- omit: endpoint.inputOmitFields
10808
+ omit: endpoint.inputOmitFields,
10809
+ operation: "write"
10846
10810
  });
10847
10811
  endpoint.returnType = this.type;
10848
10812
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10849
10813
  partial: true,
10850
10814
  pick: endpoint.outputPickFields,
10851
- omit: endpoint.outputOmitFields
10815
+ omit: endpoint.outputOmitFields,
10816
+ operation: "read"
10852
10817
  });
10853
10818
  }
10854
10819
  endpoint = this.operations.get("get");
@@ -10860,7 +10825,8 @@ var SingletonClass = class extends CrudResource {
10860
10825
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10861
10826
  partial: true,
10862
10827
  pick: endpoint.outputPickFields,
10863
- omit: endpoint.outputOmitFields
10828
+ omit: endpoint.outputOmitFields,
10829
+ operation: "read"
10864
10830
  });
10865
10831
  }
10866
10832
  endpoint = this.operations.get("update");
@@ -10870,13 +10836,15 @@ var SingletonClass = class extends CrudResource {
10870
10836
  endpoint.defineParameter("include", { type: "string", isArray: true, isBuiltin: true });
10871
10837
  endpoint.decodeInput = this.type.generateCodec("decode", {
10872
10838
  pick: endpoint.inputPickFields,
10873
- omit: endpoint.inputOmitFields
10839
+ omit: endpoint.inputOmitFields,
10840
+ operation: "write"
10874
10841
  });
10875
10842
  endpoint.returnType = this.type;
10876
10843
  endpoint.encodeReturning = endpoint.returnType.generateCodec("encode", {
10877
10844
  partial: true,
10878
10845
  pick: endpoint.outputPickFields,
10879
- omit: endpoint.outputOmitFields
10846
+ omit: endpoint.outputOmitFields,
10847
+ operation: "read"
10880
10848
  });
10881
10849
  }
10882
10850
  }
@@ -10889,8 +10857,8 @@ var SingletonClass = class extends CrudResource {
10889
10857
  type: this.type.name || "any"
10890
10858
  };
10891
10859
  }
10892
- normalizeFieldPath(path2) {
10893
- return this.type.normalizeFieldPath(path2);
10860
+ normalizeFieldPath(path) {
10861
+ return this.type.normalizeFieldPath(path);
10894
10862
  }
10895
10863
  };
10896
10864
 
@@ -11631,8 +11599,8 @@ var OpraURL = class _OpraURL {
11631
11599
  get path() {
11632
11600
  return this[kPath];
11633
11601
  }
11634
- set path(path2) {
11635
- this[kPath] = path2 instanceof OpraURLPath ? path2 : new OpraURLPath(path2);
11602
+ set path(path) {
11603
+ this[kPath] = path instanceof OpraURLPath ? path : new OpraURLPath(path);
11636
11604
  this[kContext].pathname = String(this[kPath]);
11637
11605
  this.invalidate();
11638
11606
  }
@@ -15,6 +15,8 @@ class FieldClass {
15
15
  this.default = init.default;
16
16
  this.fixed = init.fixed;
17
17
  this.required = init.required;
18
+ this.readonly = init.readonly;
19
+ this.writeonly = init.writeonly;
18
20
  this.exclusive = init.exclusive;
19
21
  this.deprecated = init.deprecated;
20
22
  this.examples = init.examples;
@@ -27,22 +29,18 @@ class FieldClass {
27
29
  default: this.default,
28
30
  fixed: this.fixed,
29
31
  required: this.required,
32
+ readonly: this.readonly,
33
+ writeonly: this.writeonly,
30
34
  exclusive: this.exclusive,
31
35
  deprecated: this.deprecated,
32
36
  examples: this.examples
33
37
  });
34
38
  }
35
- getDecoder() {
36
- if (!this._decoder)
37
- this._decoder = this.generateCodec('decode');
38
- return this._decoder;
39
- }
40
- getEncoder() {
41
- if (!this._encoder)
42
- this._encoder = this.generateCodec('encode');
43
- return this._encoder;
44
- }
45
39
  generateCodec(codec, options) {
40
+ if (options?.operation === 'read' && this.writeonly)
41
+ return vg.isUndefined();
42
+ if (options?.operation === 'write' && this.readonly)
43
+ return vg.isUndefined();
46
44
  let fn = this.type.generateCodec(codec, options);
47
45
  if (this.isArray)
48
46
  fn = vg.isArray(fn);
@@ -36,12 +36,14 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
36
36
  partial: true,
37
37
  pick: endpoint.inputPickFields,
38
38
  omit: endpoint.inputOmitFields,
39
+ operation: 'write'
39
40
  });
40
41
  endpoint.returnType = this.type;
41
42
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
42
43
  partial: true,
43
44
  pick: endpoint.outputPickFields,
44
45
  omit: endpoint.outputOmitFields,
46
+ operation: 'read'
45
47
  });
46
48
  }
47
49
  // ------------------
@@ -62,6 +64,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
62
64
  partial: true,
63
65
  pick: endpoint.outputPickFields,
64
66
  omit: endpoint.outputOmitFields,
67
+ operation: 'read'
65
68
  });
66
69
  }
67
70
  // ------------------
@@ -82,6 +85,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
82
85
  partial: true,
83
86
  pick: endpoint.outputPickFields,
84
87
  omit: endpoint.outputOmitFields,
88
+ operation: 'read'
85
89
  }));
86
90
  }
87
91
  // ------------------
@@ -94,12 +98,14 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
94
98
  endpoint.decodeInput = this.type.generateCodec('decode', {
95
99
  pick: endpoint.inputPickFields,
96
100
  omit: endpoint.inputOmitFields,
101
+ operation: 'write'
97
102
  });
98
103
  endpoint.returnType = this.type;
99
104
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
100
105
  partial: true,
101
106
  pick: endpoint.outputPickFields,
102
107
  omit: endpoint.outputOmitFields,
108
+ operation: 'read'
103
109
  });
104
110
  }
105
111
  // ------------------
@@ -110,6 +116,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
110
116
  endpoint.decodeInput = this.type.generateCodec('decode', {
111
117
  pick: endpoint.inputPickFields,
112
118
  omit: endpoint.inputOmitFields,
119
+ operation: 'write'
113
120
  });
114
121
  }
115
122
  }
@@ -19,7 +19,7 @@ class Operation extends endpoint_js_1.Endpoint {
19
19
  this.encodeReturning = vg.isAny();
20
20
  this.returnType = init.returnType instanceof data_type_js_1.DataType
21
21
  ? init.returnType : this.resource.document.getDataType(init.returnType || 'any');
22
- this.encodeReturning = this.returnType.generateCodec('encode');
22
+ this.encodeReturning = this.returnType.generateCodec('encode', { operation: 'read' });
23
23
  }
24
24
  }
25
25
  exports.Operation = Operation;
@@ -18,12 +18,14 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
18
18
  partial: true,
19
19
  pick: endpoint.inputPickFields,
20
20
  omit: endpoint.inputOmitFields,
21
+ operation: 'write'
21
22
  });
22
23
  endpoint.returnType = this.type;
23
24
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
24
25
  partial: true,
25
26
  pick: endpoint.outputPickFields,
26
27
  omit: endpoint.outputOmitFields,
28
+ operation: 'read'
27
29
  });
28
30
  }
29
31
  // ------------------
@@ -37,6 +39,7 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
37
39
  partial: true,
38
40
  pick: endpoint.outputPickFields,
39
41
  omit: endpoint.outputOmitFields,
42
+ operation: 'read'
40
43
  });
41
44
  }
42
45
  // ------------------
@@ -48,12 +51,14 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
48
51
  endpoint.decodeInput = this.type.generateCodec('decode', {
49
52
  pick: endpoint.inputPickFields,
50
53
  omit: endpoint.inputOmitFields,
54
+ operation: 'write'
51
55
  });
52
56
  endpoint.returnType = this.type;
53
57
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
54
58
  partial: true,
55
59
  pick: endpoint.outputPickFields,
56
60
  omit: endpoint.outputOmitFields,
61
+ operation: 'read'
57
62
  });
58
63
  }
59
64
  }
package/cjs/i18n/i18n.js CHANGED
@@ -3,13 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.I18n = exports.BaseI18n = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fast_tokenizer_1 = require("fast-tokenizer");
6
- const fs_1 = tslib_1.__importDefault(require("fs"));
7
- const path_1 = tslib_1.__importDefault(require("path"));
8
6
  const i18next_1 = tslib_1.__importDefault(require("@browsery/i18next"));
9
- const index_js_1 = require("../helpers/index.js");
10
7
  const string_utils_js_1 = require("./string-utils.js");
11
- exports.BaseI18n = Object.getPrototypeOf(i18next_1.default).constructor;
12
- const globalLocaleDirs = [];
8
+ exports.BaseI18n = Object.getPrototypeOf(i18next_1.default.createInstance()).constructor;
13
9
  class I18n extends exports.BaseI18n {
14
10
  async init(arg0, arg1) {
15
11
  const options = typeof arg0 === 'object' ? arg0 : {};
@@ -21,13 +17,6 @@ class I18n extends exports.BaseI18n {
21
17
  formatter.add('lowercase', (value, lng) => value.toLocaleLowerCase(lng));
22
18
  formatter.add('uppercase', (value, lng) => value.toLocaleUpperCase(lng));
23
19
  formatter.add('upperFirst', (value, lng) => value.charAt(0).toLocaleUpperCase(lng) + value.substring(1));
24
- // Load globally registered resources
25
- if (globalLocaleDirs.length)
26
- await this.loadResourceDir(globalLocaleDirs, false, true);
27
- // Load resource dirs and overwrite existing
28
- if (options?.resourceDirs?.length) {
29
- await this.loadResourceDir(options.resourceDirs, false, true);
30
- }
31
20
  // overwrite existing resources with options.resources
32
21
  if (options?.resources) {
33
22
  for (const lang of Object.keys(options.resources)) {
@@ -53,42 +42,6 @@ class I18n extends exports.BaseI18n {
53
42
  const objectStack = new WeakMap();
54
43
  return this._deepTranslate(input, objectStack, options);
55
44
  }
56
- registerLocaleDir(...dirname) {
57
- globalLocaleDirs.push(...dirname);
58
- }
59
- async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
60
- let obj;
61
- if ((0, index_js_1.isUrlString)(filePath)) {
62
- obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
63
- }
64
- else {
65
- const content = fs_1.default.readFileSync(filePath, 'utf8');
66
- obj = JSON.parse(content);
67
- }
68
- this.addResourceBundle(lang, ns, obj, deep, overwrite);
69
- }
70
- async loadResourceDir(dirnames, deep, overwrite) {
71
- for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
72
- /* istanbul ignore next */
73
- if (!(fs_1.default.existsSync(dirname)))
74
- continue;
75
- const languageDirs = fs_1.default.readdirSync(dirname);
76
- for (const lang of languageDirs) {
77
- const langDir = path_1.default.join(dirname, lang);
78
- if ((fs_1.default.statSync(langDir)).isDirectory()) {
79
- const nsDirs = fs_1.default.readdirSync(langDir);
80
- for (const nsfile of nsDirs) {
81
- const nsFilePath = path_1.default.join(langDir, nsfile);
82
- const ext = path_1.default.extname(nsfile);
83
- if (ext === '.json' && (fs_1.default.statSync(nsFilePath)).isFile()) {
84
- const ns = path_1.default.basename(nsfile, ext);
85
- await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
86
- }
87
- }
88
- }
89
- }
90
- }
91
- }
92
45
  createInstance(options = {}, callback) {
93
46
  return new I18n(options, callback);
94
47
  }
@@ -11,6 +11,8 @@ export class FieldClass {
11
11
  this.default = init.default;
12
12
  this.fixed = init.fixed;
13
13
  this.required = init.required;
14
+ this.readonly = init.readonly;
15
+ this.writeonly = init.writeonly;
14
16
  this.exclusive = init.exclusive;
15
17
  this.deprecated = init.deprecated;
16
18
  this.examples = init.examples;
@@ -23,22 +25,18 @@ export class FieldClass {
23
25
  default: this.default,
24
26
  fixed: this.fixed,
25
27
  required: this.required,
28
+ readonly: this.readonly,
29
+ writeonly: this.writeonly,
26
30
  exclusive: this.exclusive,
27
31
  deprecated: this.deprecated,
28
32
  examples: this.examples
29
33
  });
30
34
  }
31
- getDecoder() {
32
- if (!this._decoder)
33
- this._decoder = this.generateCodec('decode');
34
- return this._decoder;
35
- }
36
- getEncoder() {
37
- if (!this._encoder)
38
- this._encoder = this.generateCodec('encode');
39
- return this._encoder;
40
- }
41
35
  generateCodec(codec, options) {
36
+ if (options?.operation === 'read' && this.writeonly)
37
+ return vg.isUndefined();
38
+ if (options?.operation === 'write' && this.readonly)
39
+ return vg.isUndefined();
42
40
  let fn = this.type.generateCodec(codec, options);
43
41
  if (this.isArray)
44
42
  fn = vg.isArray(fn);
@@ -32,12 +32,14 @@ export class CollectionClass extends CrudResource {
32
32
  partial: true,
33
33
  pick: endpoint.inputPickFields,
34
34
  omit: endpoint.inputOmitFields,
35
+ operation: 'write'
35
36
  });
36
37
  endpoint.returnType = this.type;
37
38
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
38
39
  partial: true,
39
40
  pick: endpoint.outputPickFields,
40
41
  omit: endpoint.outputOmitFields,
42
+ operation: 'read'
41
43
  });
42
44
  }
43
45
  // ------------------
@@ -58,6 +60,7 @@ export class CollectionClass extends CrudResource {
58
60
  partial: true,
59
61
  pick: endpoint.outputPickFields,
60
62
  omit: endpoint.outputOmitFields,
63
+ operation: 'read'
61
64
  });
62
65
  }
63
66
  // ------------------
@@ -78,6 +81,7 @@ export class CollectionClass extends CrudResource {
78
81
  partial: true,
79
82
  pick: endpoint.outputPickFields,
80
83
  omit: endpoint.outputOmitFields,
84
+ operation: 'read'
81
85
  }));
82
86
  }
83
87
  // ------------------
@@ -90,12 +94,14 @@ export class CollectionClass extends CrudResource {
90
94
  endpoint.decodeInput = this.type.generateCodec('decode', {
91
95
  pick: endpoint.inputPickFields,
92
96
  omit: endpoint.inputOmitFields,
97
+ operation: 'write'
93
98
  });
94
99
  endpoint.returnType = this.type;
95
100
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
96
101
  partial: true,
97
102
  pick: endpoint.outputPickFields,
98
103
  omit: endpoint.outputOmitFields,
104
+ operation: 'read'
99
105
  });
100
106
  }
101
107
  // ------------------
@@ -106,6 +112,7 @@ export class CollectionClass extends CrudResource {
106
112
  endpoint.decodeInput = this.type.generateCodec('decode', {
107
113
  pick: endpoint.inputPickFields,
108
114
  omit: endpoint.inputOmitFields,
115
+ operation: 'write'
109
116
  });
110
117
  }
111
118
  }
@@ -15,6 +15,6 @@ export class Operation extends Endpoint {
15
15
  this.encodeReturning = vg.isAny();
16
16
  this.returnType = init.returnType instanceof DataType
17
17
  ? init.returnType : this.resource.document.getDataType(init.returnType || 'any');
18
- this.encodeReturning = this.returnType.generateCodec('encode');
18
+ this.encodeReturning = this.returnType.generateCodec('encode', { operation: 'read' });
19
19
  }
20
20
  }
@@ -15,12 +15,14 @@ export class SingletonClass extends CrudResource {
15
15
  partial: true,
16
16
  pick: endpoint.inputPickFields,
17
17
  omit: endpoint.inputOmitFields,
18
+ operation: 'write'
18
19
  });
19
20
  endpoint.returnType = this.type;
20
21
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
21
22
  partial: true,
22
23
  pick: endpoint.outputPickFields,
23
24
  omit: endpoint.outputOmitFields,
25
+ operation: 'read'
24
26
  });
25
27
  }
26
28
  // ------------------
@@ -34,6 +36,7 @@ export class SingletonClass extends CrudResource {
34
36
  partial: true,
35
37
  pick: endpoint.outputPickFields,
36
38
  omit: endpoint.outputOmitFields,
39
+ operation: 'read'
37
40
  });
38
41
  }
39
42
  // ------------------
@@ -45,12 +48,14 @@ export class SingletonClass extends CrudResource {
45
48
  endpoint.decodeInput = this.type.generateCodec('decode', {
46
49
  pick: endpoint.inputPickFields,
47
50
  omit: endpoint.inputOmitFields,
51
+ operation: 'write'
48
52
  });
49
53
  endpoint.returnType = this.type;
50
54
  endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
51
55
  partial: true,
52
56
  pick: endpoint.outputPickFields,
53
57
  omit: endpoint.outputOmitFields,
58
+ operation: 'read'
54
59
  });
55
60
  }
56
61
  }
package/esm/i18n/i18n.js CHANGED
@@ -1,11 +1,7 @@
1
1
  import { splitString, tokenize } from 'fast-tokenizer';
2
- import fs from 'fs';
3
- import path from 'path';
4
2
  import i18next from '@browsery/i18next';
5
- import { isUrlString } from '../helpers/index.js';
6
3
  import { unescapeString } from './string-utils.js';
7
- export const BaseI18n = Object.getPrototypeOf(i18next).constructor;
8
- const globalLocaleDirs = [];
4
+ export const BaseI18n = Object.getPrototypeOf(i18next.createInstance()).constructor;
9
5
  export class I18n extends BaseI18n {
10
6
  async init(arg0, arg1) {
11
7
  const options = typeof arg0 === 'object' ? arg0 : {};
@@ -17,13 +13,6 @@ export class I18n extends BaseI18n {
17
13
  formatter.add('lowercase', (value, lng) => value.toLocaleLowerCase(lng));
18
14
  formatter.add('uppercase', (value, lng) => value.toLocaleUpperCase(lng));
19
15
  formatter.add('upperFirst', (value, lng) => value.charAt(0).toLocaleUpperCase(lng) + value.substring(1));
20
- // Load globally registered resources
21
- if (globalLocaleDirs.length)
22
- await this.loadResourceDir(globalLocaleDirs, false, true);
23
- // Load resource dirs and overwrite existing
24
- if (options?.resourceDirs?.length) {
25
- await this.loadResourceDir(options.resourceDirs, false, true);
26
- }
27
16
  // overwrite existing resources with options.resources
28
17
  if (options?.resources) {
29
18
  for (const lang of Object.keys(options.resources)) {
@@ -49,42 +38,6 @@ export class I18n extends BaseI18n {
49
38
  const objectStack = new WeakMap();
50
39
  return this._deepTranslate(input, objectStack, options);
51
40
  }
52
- registerLocaleDir(...dirname) {
53
- globalLocaleDirs.push(...dirname);
54
- }
55
- async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
56
- let obj;
57
- if (isUrlString(filePath)) {
58
- obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
59
- }
60
- else {
61
- const content = fs.readFileSync(filePath, 'utf8');
62
- obj = JSON.parse(content);
63
- }
64
- this.addResourceBundle(lang, ns, obj, deep, overwrite);
65
- }
66
- async loadResourceDir(dirnames, deep, overwrite) {
67
- for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
68
- /* istanbul ignore next */
69
- if (!(fs.existsSync(dirname)))
70
- continue;
71
- const languageDirs = fs.readdirSync(dirname);
72
- for (const lang of languageDirs) {
73
- const langDir = path.join(dirname, lang);
74
- if ((fs.statSync(langDir)).isDirectory()) {
75
- const nsDirs = fs.readdirSync(langDir);
76
- for (const nsfile of nsDirs) {
77
- const nsFilePath = path.join(langDir, nsfile);
78
- const ext = path.extname(nsfile);
79
- if (ext === '.json' && (fs.statSync(nsFilePath)).isFile()) {
80
- const ns = path.basename(nsfile, ext);
81
- await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
82
- }
83
- }
84
- }
85
- }
86
- }
87
- }
88
41
  createInstance(options = {}, callback) {
89
42
  return new I18n(options, callback);
90
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "0.27.2",
3
+ "version": "0.28.1",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "putil-varhelpers": "^1.6.5",
46
46
  "reflect-metadata": "^0.1.13",
47
47
  "uid": "^2.0.1",
48
- "valgen": "^4.0.0"
48
+ "valgen": "^4.0.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@browsery/fs": "^0.4.0",
@@ -41,5 +41,6 @@ export declare namespace DataType {
41
41
  pick?: string[];
42
42
  omit?: string[];
43
43
  partial?: boolean;
44
+ operation?: 'read' | 'write';
44
45
  }
45
46
  }
@@ -15,6 +15,8 @@ export declare class FieldClass {
15
15
  default?: any;
16
16
  fixed?: string | number;
17
17
  required?: boolean;
18
+ readonly?: boolean;
19
+ writeonly?: boolean;
18
20
  exclusive?: boolean;
19
21
  deprecated?: boolean | string;
20
22
  examples?: any[] | Record<string, any>;
@@ -22,7 +24,5 @@ export declare class FieldClass {
22
24
  exportSchema(options?: {
23
25
  webSafe?: boolean;
24
26
  }): OpraSchema.Field;
25
- getDecoder(): vg.Validator;
26
- getEncoder(): vg.Validator;
27
27
  generateCodec(codec: 'decode' | 'encode', options?: DataType.GenerateCodecOptions): vg.Validator;
28
28
  }
@@ -18,9 +18,6 @@ export declare class I18n extends BaseI18n {
18
18
  init(callback?: InitCallback): Promise<TranslateFunction>;
19
19
  init(options: InitOptions, callback?: InitCallback): Promise<TranslateFunction>;
20
20
  deep(input: any, options?: DeepTranslateOptions): any;
21
- registerLocaleDir(...dirname: string[]): void;
22
- loadResourceBundle(lang: string, ns: string, filePath: string, deep?: boolean, overwrite?: boolean): Promise<void>;
23
- loadResourceDir(dirnames: string | string[], deep?: boolean, overwrite?: boolean): Promise<void>;
24
21
  createInstance(options: {} | undefined, callback: any): I18n;
25
22
  static createInstance(options?: InitOptions, callback?: InitCallback): I18n;
26
23
  protected _deepTranslate(input: any, objectStack: WeakMap<object, any>, options?: DeepTranslateOptions): any;
@@ -9,6 +9,8 @@ export type Field = {
9
9
  isArray?: boolean;
10
10
  default?: any;
11
11
  required?: boolean;
12
+ readonly?: boolean;
13
+ writeonly?: boolean;
12
14
  format?: string;
13
15
  fixed?: string | number;
14
16
  examples?: any[] | Record<string, any>;