nesoi 3.0.0 → 3.0.3

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 (185) hide show
  1. package/README.md +10 -0
  2. package/lib/adapters/postgres/src/migrator/bucket.d.ts +20 -0
  3. package/lib/adapters/postgres/src/migrator/bucket.js +184 -0
  4. package/lib/adapters/postgres/src/migrator/csv.d.ts +7 -0
  5. package/lib/adapters/postgres/src/migrator/csv.js +72 -0
  6. package/lib/adapters/postgres/src/migrator/migration.d.ts +2 -18
  7. package/lib/adapters/postgres/src/migrator/migration.js +10 -158
  8. package/lib/adapters/postgres/src/migrator/migrator.js +8 -5
  9. package/lib/adapters/postgres/src/migrator/runner.d.ts +16 -6
  10. package/lib/adapters/postgres/src/migrator/runner.js +103 -34
  11. package/lib/adapters/postgres/src/postgres.bucket_adapter.d.ts +19 -22
  12. package/lib/adapters/postgres/src/postgres.bucket_adapter.js +116 -100
  13. package/lib/adapters/postgres/src/postgres.cli.d.ts +23 -3
  14. package/lib/adapters/postgres/src/postgres.cli.js +70 -10
  15. package/lib/adapters/postgres/src/postgres.config.d.ts +5 -0
  16. package/lib/adapters/postgres/src/postgres.config.js +2 -0
  17. package/lib/adapters/postgres/src/postgres.nql.d.ts +7 -3
  18. package/lib/adapters/postgres/src/postgres.nql.js +86 -32
  19. package/lib/adapters/postgres/src/postgres.provider.d.ts +18 -0
  20. package/lib/adapters/postgres/src/postgres.provider.js +77 -0
  21. package/lib/adapters/postgres/test/postgres.bucket_adapter.test.js +76 -39
  22. package/lib/compiler/apps/monolyth/monolyth_compiler.d.ts +3 -0
  23. package/lib/compiler/apps/monolyth/monolyth_compiler.js +24 -0
  24. package/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.js +2 -1
  25. package/lib/compiler/apps/monolyth/stages/5_dump_cli_stage.js +1 -1
  26. package/lib/compiler/elements/bucket.element.js +26 -11
  27. package/lib/compiler/elements/constants.element.js +1 -1
  28. package/lib/compiler/elements/element.d.ts +2 -0
  29. package/lib/compiler/elements/message.element.js +4 -4
  30. package/lib/compiler/helpers/dump_helpers.js +5 -2
  31. package/lib/compiler/stages/7_dump_stage.js +2 -0
  32. package/lib/compiler/treeshake.js +9 -37
  33. package/lib/compiler/typescript/bridge/extract.js +12 -0
  34. package/lib/compiler/typescript/bridge/inject.js +3 -0
  35. package/lib/compiler/typescript/bridge/organize.js +3 -3
  36. package/lib/elements/blocks/block.builder.js +4 -2
  37. package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +22 -20
  38. package/lib/elements/blocks/job/internal/resource_job.d.ts +2 -1
  39. package/lib/elements/blocks/job/internal/resource_job.js +17 -4
  40. package/lib/elements/blocks/job/job.js +3 -0
  41. package/lib/elements/blocks/job/job.types.d.ts +7 -0
  42. package/lib/elements/blocks/job/job.types.js +2 -0
  43. package/lib/elements/blocks/machine/machine.js +3 -2
  44. package/lib/elements/blocks/resource/resource.builder.js +2 -4
  45. package/lib/elements/blocks/resource/resource.d.ts +5 -3
  46. package/lib/elements/blocks/resource/resource.js +26 -17
  47. package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +2 -1
  48. package/lib/elements/edge/controller/adapters/controller_adapter.js +11 -2
  49. package/lib/elements/edge/controller/controller.builder.d.ts +4 -5
  50. package/lib/elements/edge/controller/controller.builder.js +7 -7
  51. package/lib/elements/edge/controller/controller.d.ts +2 -1
  52. package/lib/elements/edge/controller/controller.js +8 -6
  53. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +61 -23
  54. package/lib/elements/entities/bucket/adapters/bucket_adapter.js +22 -13
  55. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +21 -22
  56. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +68 -2
  57. package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +10 -6
  58. package/lib/elements/entities/bucket/adapters/memory.nql.js +38 -3
  59. package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.d.ts +0 -20
  60. package/lib/elements/entities/bucket/adapters/slow_memory.bucket_adapter.js +46 -30
  61. package/lib/elements/entities/bucket/bucket.builder.d.ts +8 -2
  62. package/lib/elements/entities/bucket/bucket.builder.js +13 -19
  63. package/lib/elements/entities/bucket/bucket.config.d.ts +5 -1
  64. package/lib/elements/entities/bucket/bucket.d.ts +180 -19
  65. package/lib/elements/entities/bucket/bucket.js +658 -48
  66. package/lib/elements/entities/bucket/bucket.schema.d.ts +7 -1
  67. package/lib/elements/entities/bucket/bucket.schema.js +2 -1
  68. package/lib/elements/entities/bucket/bucket.types.d.ts +2 -7
  69. package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +6 -2
  70. package/lib/elements/entities/bucket/cache/bucket_cache.js +12 -12
  71. package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +32 -5
  72. package/lib/elements/entities/bucket/graph/bucket_graph.js +80 -111
  73. package/lib/elements/entities/bucket/graph/bucket_graph.schema.d.ts +3 -6
  74. package/lib/elements/entities/bucket/graph/bucket_graph.schema.js +1 -4
  75. package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +3 -7
  76. package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.js +6 -2
  77. package/lib/elements/entities/bucket/model/bucket_model.builder.js +1 -1
  78. package/lib/elements/entities/bucket/model/bucket_model.convert.js +3 -3
  79. package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +37 -8
  80. package/lib/elements/entities/bucket/model/bucket_model.schema.js +25 -4
  81. package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +33 -14
  82. package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +56 -13
  83. package/lib/elements/entities/bucket/query/nql.schema.d.ts +1 -0
  84. package/lib/elements/entities/bucket/query/nql_compiler.js +13 -2
  85. package/lib/elements/entities/bucket/query/nql_engine.d.ts +11 -4
  86. package/lib/elements/entities/bucket/query/nql_engine.js +20 -11
  87. package/lib/elements/entities/bucket/view/bucket_view.js +63 -35
  88. package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +5 -2
  89. package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +6 -2
  90. package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +21 -15
  91. package/lib/elements/entities/constants/constants.schema.d.ts +1 -1
  92. package/lib/elements/entities/drive/drive_adapter.d.ts +36 -0
  93. package/lib/elements/entities/drive/drive_adapter.js +10 -0
  94. package/lib/elements/entities/drive/local.drive_adapter.d.ts +8 -0
  95. package/lib/elements/entities/drive/local.drive_adapter.js +28 -0
  96. package/lib/elements/entities/message/message.schema.d.ts +1 -0
  97. package/lib/elements/entities/message/message.schema.js +33 -0
  98. package/lib/elements/entities/message/message_parser.d.ts +5 -1
  99. package/lib/elements/entities/message/message_parser.js +56 -35
  100. package/lib/elements/entities/message/template/message_template.schema.d.ts +10 -8
  101. package/lib/elements/entities/message/template/message_template_field.builder.d.ts +16 -6
  102. package/lib/elements/entities/message/template/message_template_field.builder.js +25 -0
  103. package/lib/elements/entities/message/template/message_template_parser.js +2 -1
  104. package/lib/engine/apps/app.config.d.ts +32 -11
  105. package/lib/engine/apps/app.config.js +12 -0
  106. package/lib/engine/apps/app.d.ts +2 -0
  107. package/lib/engine/apps/app.js +3 -0
  108. package/lib/engine/apps/inline.app.d.ts +5 -3
  109. package/lib/engine/apps/inline.app.js +27 -12
  110. package/lib/engine/apps/monolyth/monolyth.app.d.ts +4 -2
  111. package/lib/engine/apps/monolyth/monolyth.app.js +22 -10
  112. package/lib/engine/auth/authn.d.ts +5 -1
  113. package/lib/engine/auth/zero.authn_provider.d.ts +4 -2
  114. package/lib/engine/auth/zero.authn_provider.js +2 -2
  115. package/lib/engine/cli/cli.d.ts +3 -1
  116. package/lib/engine/cli/cli.js +22 -3
  117. package/lib/engine/cli/cli_adapter.d.ts +2 -1
  118. package/lib/engine/cli/cli_adapter.js +2 -1
  119. package/lib/engine/cli/cli_input.d.ts +19 -0
  120. package/lib/engine/cli/cli_input.js +207 -0
  121. package/lib/engine/cli/ui.d.ts +1 -1
  122. package/lib/engine/cli/ui.js +2 -2
  123. package/lib/engine/daemon.d.ts +3 -2
  124. package/lib/engine/daemon.js +14 -2
  125. package/lib/engine/data/date.js +2 -2
  126. package/lib/engine/data/datetime.d.ts +40 -4
  127. package/lib/engine/data/datetime.js +70 -11
  128. package/lib/engine/data/decimal.d.ts +1 -1
  129. package/lib/engine/data/decimal.js +3 -3
  130. package/lib/engine/data/error.d.ts +21 -4
  131. package/lib/engine/data/error.js +23 -7
  132. package/lib/engine/data/file.d.ts +23 -0
  133. package/lib/engine/data/file.js +53 -0
  134. package/lib/engine/data/json.d.ts +6 -0
  135. package/lib/engine/data/json.js +26 -0
  136. package/lib/engine/data/obj.d.ts +1 -1
  137. package/lib/engine/data/trash.d.ts +14 -0
  138. package/lib/engine/data/trash.js +2 -0
  139. package/lib/engine/data/tree.d.ts +7 -12
  140. package/lib/engine/data/tree.js +101 -49
  141. package/lib/engine/module.d.ts +2 -1
  142. package/lib/engine/module.js +2 -5
  143. package/lib/engine/space.d.ts +1 -0
  144. package/lib/engine/space.js +6 -0
  145. package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +156 -24
  146. package/lib/engine/transaction/nodes/bucket.trx_node.js +297 -467
  147. package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +4 -2
  148. package/lib/engine/transaction/nodes/bucket_query.trx_node.js +27 -15
  149. package/lib/engine/transaction/nodes/job.trx_node.d.ts +2 -1
  150. package/lib/engine/transaction/nodes/job.trx_node.js +6 -0
  151. package/lib/engine/transaction/trx.d.ts +5 -2
  152. package/lib/engine/transaction/trx.js +2 -2
  153. package/lib/engine/transaction/trx_engine.config.d.ts +1 -3
  154. package/lib/engine/transaction/trx_engine.d.ts +2 -2
  155. package/lib/engine/transaction/trx_engine.js +14 -11
  156. package/lib/engine/transaction/trx_node.d.ts +14 -4
  157. package/lib/engine/transaction/trx_node.js +50 -8
  158. package/lib/engine/tree.d.ts +1 -1
  159. package/lib/engine/util/crypto.d.ts +50 -0
  160. package/lib/engine/util/crypto.js +89 -0
  161. package/lib/engine/util/deep.d.ts +5 -0
  162. package/lib/engine/util/deep.js +46 -0
  163. package/lib/engine/util/dotenv.d.ts +2 -8
  164. package/lib/engine/util/dotenv.js +14 -36
  165. package/lib/engine/util/hash.d.ts +3 -0
  166. package/lib/engine/util/hash.js +23 -0
  167. package/lib/engine/util/log.js +1 -1
  168. package/lib/engine/util/mime.d.ts +10 -0
  169. package/lib/engine/util/mime.js +389 -0
  170. package/lib/engine/util/parse.d.ts +6 -5
  171. package/lib/engine/util/parse.js +16 -15
  172. package/lib/engine/util/path.d.ts +3 -0
  173. package/lib/engine/util/path.js +92 -0
  174. package/lib/engine/util/rules.d.ts +4 -0
  175. package/lib/engine/util/rules.js +12 -0
  176. package/package.json +1 -1
  177. package/tools/compile.js +2 -2
  178. package/tools/dotenv.d.ts +1 -0
  179. package/tools/dotenv.js +4 -0
  180. package/tools/joaquin/job.d.ts +5 -5
  181. package/tools/joaquin/mock.d.ts +23 -2
  182. package/tools/joaquin/mock.js +127 -21
  183. package/tsconfig.build.tsbuildinfo +1 -1
  184. package/lib/adapters/postgres/test/postgres.bucket_query.test.d.ts +0 -0
  185. package/lib/adapters/postgres/test/postgres.bucket_query.test.js +0 -136
@@ -20,9 +20,9 @@ class Daemon {
20
20
  }
21
21
  return new DaemonTrx(trxEngine);
22
22
  }
23
- async cli() {
23
+ async cli(cmd) {
24
24
  this._cli = new cli_1.CLI(this, this.app?.cli);
25
- await this._cli.run();
25
+ await this._cli.run(cmd);
26
26
  }
27
27
  bindControllers() {
28
28
  log_1.Log.info('daemon', this.name, 'Binding controllers');
@@ -34,10 +34,22 @@ class Daemon {
34
34
  }
35
35
  }
36
36
  }
37
+ static async destroy(daemon) {
38
+ log_1.Log.info('daemon', this.name, 'Stop');
39
+ for (const key in daemon.providers) {
40
+ const provider = daemon.providers[key];
41
+ await provider.__down(provider);
42
+ delete daemon.providers[key];
43
+ }
44
+ for (const key in daemon.trxEngines) {
45
+ delete daemon.trxEngines[key];
46
+ }
47
+ }
37
48
  static reload(daemon, trxEngines, providers) {
38
49
  log_1.Log.info('daemon', this.name, 'Reloaded');
39
50
  daemon.trxEngines = trxEngines;
40
51
  daemon.providers = providers;
52
+ daemon.bindControllers();
41
53
  }
42
54
  static get(daemon, key) {
43
55
  return daemon?.[key];
@@ -9,8 +9,8 @@ class NesoiDate {
9
9
  this.year = year;
10
10
  }
11
11
  static fromISO(iso) {
12
- // TODO: Check invalid ISO
13
- const match = iso.match(/(\d{4})-([01]\d)-([0-3]\d)/);
12
+ const match = iso.match(/(\d{4})-(\d{2})-(\d{2})/);
13
+ // TODO: Check invalid date
14
14
  if (!match) {
15
15
  throw error_1.NesoiError.Data.InvalidISOString({ value: iso });
16
16
  }
@@ -1,12 +1,48 @@
1
1
  export declare class NesoiDatetime {
2
+ static tz: {
3
+ '-12:00': string;
4
+ '-11:00': string;
5
+ '-10:00': string;
6
+ '-07:00': string;
7
+ '-06:00': string;
8
+ '-05:00': string;
9
+ '-04:00': string;
10
+ '-03:00': string;
11
+ '-02:00': string;
12
+ '-01:00': string;
13
+ Z: string;
14
+ '+01:00': string;
15
+ '+02:00': string;
16
+ '+03:00': string;
17
+ '+04:00': string;
18
+ '+05:00': string;
19
+ '+06:00': string;
20
+ '+07:00': string;
21
+ '+08:00': string;
22
+ '+09:00': string;
23
+ '+10:00': string;
24
+ '+11:00': string;
25
+ '+12:00': string;
26
+ '+13:00': string;
27
+ };
2
28
  /**
3
- * Time in milliseconds since 1970-01-01
29
+ * Time in milliseconds since 1970-01-01T00:00:00.000Z
4
30
  */
5
31
  epoch: number;
6
- constructor(jsDate?: Date);
32
+ /**
33
+ * Timezone represented as string (Z, -03, +05, ...)
34
+ */
35
+ tz: keyof typeof NesoiDatetime.tz;
36
+ constructor(epoch?: number, tz?: keyof typeof NesoiDatetime.tz);
37
+ toISO(): string;
38
+ /**
39
+ * Parse a timestamp from ISO 8601 format.
40
+ *
41
+ * Example: `2025-04-16T23:04:42.000-03:00`
42
+ */
7
43
  static fromISO(iso: string): NesoiDatetime;
8
44
  static now(): NesoiDatetime;
9
45
  static isoNow(): string;
10
- static shortNow(): string;
11
- toISO(): string;
46
+ static shortIsoNow(): string;
47
+ plus(period: `${number} ${'second' | 'minute' | 'hour' | 'day' | 'week' | 'month'}${'s' | ''}`): this;
12
48
  }
@@ -3,29 +3,88 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NesoiDatetime = void 0;
4
4
  const error_1 = require("./error");
5
5
  class NesoiDatetime {
6
- constructor(jsDate) {
7
- this.epoch = (jsDate || new Date()).getTime();
6
+ constructor(epoch, tz = 'Z') {
7
+ this.epoch = epoch || new Date().getTime();
8
+ this.tz = tz;
8
9
  }
10
+ // Dump
11
+ toISO() {
12
+ return new Date(this.epoch).toLocaleString('sv-SE', {
13
+ timeZone: NesoiDatetime.tz[this.tz],
14
+ year: 'numeric',
15
+ month: 'numeric',
16
+ day: 'numeric',
17
+ hour: 'numeric',
18
+ minute: 'numeric',
19
+ second: 'numeric',
20
+ fractionalSecondDigits: 3
21
+ })
22
+ .replace(' ', 'T')
23
+ .replace(',', '.')
24
+ + this.tz;
25
+ }
26
+ /**
27
+ * Parse a timestamp from ISO 8601 format.
28
+ *
29
+ * Example: `2025-04-16T23:04:42.000-03:00`
30
+ */
9
31
  static fromISO(iso) {
10
- // TODO: Check invalid ISO
11
- const match = iso.match(/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/);
32
+ const match = iso.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(([-+]\d{2})|Z)?(:00)?$/);
33
+ // TODO: Check invalid datetimes
12
34
  if (!match) {
13
35
  throw error_1.NesoiError.Data.InvalidISOString({ value: iso });
14
36
  }
15
- const jsDate = new Date(iso);
16
- return new NesoiDatetime(jsDate);
37
+ let tz = match[8];
38
+ if (!tz) {
39
+ iso += 'Z';
40
+ tz = 'Z';
41
+ }
42
+ if (tz !== 'Z') {
43
+ if (!match[10]) {
44
+ iso += ':00';
45
+ }
46
+ tz += ':00';
47
+ }
48
+ const jsDate = Date.parse(iso);
49
+ return new NesoiDatetime(jsDate, tz);
17
50
  }
18
51
  static now() {
19
52
  return new NesoiDatetime();
20
53
  }
21
54
  static isoNow() {
22
- return new Date().toISOString();
55
+ return new NesoiDatetime().toISO();
23
56
  }
24
- static shortNow() {
25
- return new Date().toISOString().slice(5, 19);
57
+ static shortIsoNow() {
58
+ return new NesoiDatetime().toISO().slice(5, 19);
26
59
  }
27
- toISO() {
28
- return new Date(this.epoch).toISOString();
60
+ plus(period) {
61
+ return this;
29
62
  }
30
63
  }
31
64
  exports.NesoiDatetime = NesoiDatetime;
65
+ NesoiDatetime.tz = {
66
+ '-12:00': 'Etc/GMT+12',
67
+ '-11:00': 'Etc/GMT+11',
68
+ '-10:00': 'Etc/GMT+10',
69
+ '-07:00': 'Etc/GMT+7',
70
+ '-06:00': 'Etc/GMT+6',
71
+ '-05:00': 'Etc/GMT+5',
72
+ '-04:00': 'Etc/GMT+4',
73
+ '-03:00': 'Etc/GMT+3',
74
+ '-02:00': 'Etc/GMT+2',
75
+ '-01:00': 'Etc/GMT+1',
76
+ 'Z': 'Etc/GMT',
77
+ '+01:00': 'Etc/GMT-1',
78
+ '+02:00': 'Etc/GMT-2',
79
+ '+03:00': 'Etc/GMT-3',
80
+ '+04:00': 'Etc/GMT-4',
81
+ '+05:00': 'Etc/GMT-5',
82
+ '+06:00': 'Etc/GMT-6',
83
+ '+07:00': 'Etc/GMT-7',
84
+ '+08:00': 'Etc/GMT-8',
85
+ '+09:00': 'Etc/GMT-9',
86
+ '+10:00': 'Etc/GMT-10',
87
+ '+11:00': 'Etc/GMT-11',
88
+ '+12:00': 'Etc/GMT-12',
89
+ '+13:00': 'Etc/GMT-13',
90
+ };
@@ -1,4 +1,4 @@
1
- export declare class Decimal {
1
+ export declare class NesoiDecimal {
2
2
  private neg;
3
3
  private left;
4
4
  private right;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Decimal = void 0;
3
+ exports.NesoiDecimal = void 0;
4
4
  const error_1 = require("./error");
5
- class Decimal {
5
+ class NesoiDecimal {
6
6
  constructor(value, pLeft = 12, pRight = 12) {
7
7
  this.neg = false;
8
8
  let payload = value.trim();
@@ -67,4 +67,4 @@ class Decimal {
67
67
  return (this.neg ? -1 : 1) * (this.left + this.right * this.r_exp);
68
68
  }
69
69
  }
70
- exports.Decimal = Decimal;
70
+ exports.NesoiDecimal = NesoiDecimal;
@@ -22,7 +22,10 @@ export declare namespace NesoiError {
22
22
  function UnknownGraphLink(name: string): BaseError;
23
23
  function UnknownViewName(name: string): BaseError;
24
24
  function NoChildrenOnViewGroup(name: string): BaseError;
25
- function CompositionWithPivotNotAllowed(): BaseError;
25
+ function CompositionThroughPivotNotAllowed($: {
26
+ bucket: string;
27
+ link: string;
28
+ }): BaseError;
26
29
  }
27
30
  namespace Message {
28
31
  function UnknownTemplateFieldType(type: string): BaseError;
@@ -55,6 +58,7 @@ export declare namespace NesoiError {
55
58
  namespace Trx {
56
59
  function ModuleNotFound(module: string): BaseError;
57
60
  function NodeNotFound(node: string, trx: string): BaseError;
61
+ function NotAuthenticated($: {}): BaseError;
58
62
  }
59
63
  namespace Bucket {
60
64
  function InvalidId($: {
@@ -84,6 +88,10 @@ export declare namespace NesoiError {
84
88
  bucket: string;
85
89
  link: string;
86
90
  }): BaseError;
91
+ function FieldNotFound($: {
92
+ path: string;
93
+ bucket: string;
94
+ }): BaseError;
87
95
  namespace Graph {
88
96
  function LinkNotFound($: {
89
97
  bucket: string;
@@ -93,7 +101,11 @@ export declare namespace NesoiError {
93
101
  function LinkManyRefOffSelfWithArrayValue(link: string): BaseError;
94
102
  function LinkOneWithArrayValue(link: string): BaseError;
95
103
  function PivotValueIsUndefined(link: string): BaseError;
96
- function RequiredLinkNotFound(link: string, value: any): BaseError;
104
+ function RequiredLinkNotFound($: {
105
+ bucket: string;
106
+ link: string;
107
+ id: number | string;
108
+ }): BaseError;
97
109
  }
98
110
  namespace Query {
99
111
  function NoResults($: {
@@ -112,6 +124,11 @@ export declare namespace NesoiError {
112
124
  index: (string | number)[];
113
125
  }): BaseError;
114
126
  }
127
+ namespace Drive {
128
+ function NoAdapter($: {
129
+ bucket: string;
130
+ }): BaseError;
131
+ }
115
132
  }
116
133
  namespace Data {
117
134
  function InvalidISOString($: {
@@ -167,11 +184,11 @@ export declare namespace NesoiError {
167
184
  path: string;
168
185
  value: any;
169
186
  }): BaseError;
170
- function RuleFailed(rule: $MessageTemplateRule<any, any>, error: string): BaseError;
187
+ function RuleFailed(rule: $MessageTemplateRule, error: string): BaseError;
171
188
  function FileTooBig(prop: {
172
189
  name: string;
173
190
  alias?: string;
174
- }, maxSize: number): BaseError;
191
+ }, maxsize: number): BaseError;
175
192
  function FileExtNotAllowed(prop: {
176
193
  name: string;
177
194
  alias?: string;
@@ -20,6 +20,7 @@ var NesoiError;
20
20
  Status[Status["BAD_REQUEST"] = 400] = "BAD_REQUEST";
21
21
  Status[Status["NOT_FOUND"] = 404] = "NOT_FOUND";
22
22
  Status[Status["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
23
+ Status[Status["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
23
24
  Status[Status["INTERNAL_ERROR"] = 500] = "INTERNAL_ERROR";
24
25
  })(Status || (Status = {}));
25
26
  let Builder;
@@ -49,10 +50,10 @@ var NesoiError;
49
50
  return new BaseError('Builder.Bucket.NoChildrenOnViewGroup', `Bucket view group ${name} has no children`, Status.NOT_FOUND);
50
51
  }
51
52
  Bucket.NoChildrenOnViewGroup = NoChildrenOnViewGroup;
52
- function CompositionWithPivotNotAllowed() {
53
- return new BaseError('Builder.Bucket.CompositionWithPivotNotAllowed', 'Composition with pivot is not allowed', Status.NOT_FOUND);
53
+ function CompositionThroughPivotNotAllowed($) {
54
+ return new BaseError('Builder.Bucket.CompositionThroughPivotNotAllowed', `Link '${$.link}' on bucket '${$.bucket}' passes through pivot, so it cannot be a composition`, Status.INTERNAL_ERROR);
54
55
  }
55
- Bucket.CompositionWithPivotNotAllowed = CompositionWithPivotNotAllowed;
56
+ Bucket.CompositionThroughPivotNotAllowed = CompositionThroughPivotNotAllowed;
56
57
  })(Bucket = Builder.Bucket || (Builder.Bucket = {}));
57
58
  let Message;
58
59
  (function (Message) {
@@ -148,6 +149,10 @@ var NesoiError;
148
149
  return new BaseError('Trx.NodeNotFoundOnTrx', `Node ${node} not found on transaction ${trx}`, Status.NOT_FOUND);
149
150
  }
150
151
  Trx.NodeNotFound = NodeNotFound;
152
+ function NotAuthenticated($) {
153
+ return new BaseError('Trx.NotAuthenticated', 'Unauthorized', Status.UNAUTHORIZED, $);
154
+ }
155
+ Trx.NotAuthenticated = NotAuthenticated;
151
156
  })(Trx = NesoiError.Trx || (NesoiError.Trx = {}));
152
157
  /*
153
158
  Elements / Entities
@@ -178,6 +183,10 @@ var NesoiError;
178
183
  return new BaseError('Bucket.CompositionValueShouldBeArray', `Request to ${$.method} bucket '${$.bucket}' failed, composition for link ${$.link} should be an array`, Status.BAD_REQUEST, $);
179
184
  }
180
185
  Bucket.CompositionValueShouldBeArray = CompositionValueShouldBeArray;
186
+ function FieldNotFound($) {
187
+ return new BaseError('Bucket.FieldNotFound', `Field '${$.path}' not found on bucket '${$.bucket}'`, Status.NOT_FOUND, $);
188
+ }
189
+ Bucket.FieldNotFound = FieldNotFound;
181
190
  let Graph;
182
191
  (function (Graph) {
183
192
  function LinkNotFound($) {
@@ -200,8 +209,8 @@ var NesoiError;
200
209
  return new BaseError('Bucket.Graph.PivotValueIsUndefined', `Link ${link} has a pivot value with undefined/null on the other id`, Status.NOT_FOUND);
201
210
  }
202
211
  Graph.PivotValueIsUndefined = PivotValueIsUndefined;
203
- function RequiredLinkNotFound(link, value) {
204
- return new BaseError('Bucket.Graph.RequiredLinkNotFound', `Link ${link} value not found for value ${value}`, Status.NOT_FOUND);
212
+ function RequiredLinkNotFound($) {
213
+ return new BaseError('Bucket.Graph.RequiredLinkNotFound', `Link '${$.link}' of '${$.bucket}' not found for object with id ${$.id}`, Status.PRECONDITION_FAILED, $);
205
214
  }
206
215
  Graph.RequiredLinkNotFound = RequiredLinkNotFound;
207
216
  })(Graph = Bucket.Graph || (Bucket.Graph = {}));
@@ -239,6 +248,13 @@ var NesoiError;
239
248
  }
240
249
  Fieldpath.InvalidIndexLength = InvalidIndexLength;
241
250
  })(Fieldpath = Bucket.Fieldpath || (Bucket.Fieldpath = {}));
251
+ let Drive;
252
+ (function (Drive) {
253
+ function NoAdapter($) {
254
+ return new BaseError('Bucket.Drive.NoAdapter', `Bucket '${$.bucket}' needs a DriveAdapter configured to handle files.`, Status.BAD_REQUEST, $);
255
+ }
256
+ Drive.NoAdapter = NoAdapter;
257
+ })(Drive = Bucket.Drive || (Bucket.Drive = {}));
242
258
  })(Bucket = NesoiError.Bucket || (NesoiError.Bucket = {}));
243
259
  let Data;
244
260
  (function (Data) {
@@ -301,8 +317,8 @@ var NesoiError;
301
317
  return new BaseError('Message.RuleFailed', error);
302
318
  }
303
319
  Message.RuleFailed = RuleFailed;
304
- function FileTooBig(prop, maxSize) {
305
- return new BaseError('Message.FileTooBig', `${prop.alias || prop.name} size exceeds max (${maxSize})`);
320
+ function FileTooBig(prop, maxsize) {
321
+ return new BaseError('Message.FileTooBig', `${prop.alias || prop.name} size exceeds max (${maxsize})`);
306
322
  }
307
323
  Message.FileTooBig = FileTooBig;
308
324
  function FileExtNotAllowed(prop, options) {
@@ -0,0 +1,23 @@
1
+ export declare class NesoiFile {
2
+ __nesoi_file: boolean;
3
+ filepath: string;
4
+ filename: string;
5
+ extname: string;
6
+ mimetype: string | null;
7
+ size: number;
8
+ originalFilename: string | null;
9
+ newFilename: string;
10
+ mtime: Date | null;
11
+ hashAlgorithm: false | 'sha1' | 'md5' | 'sha256';
12
+ private _hash;
13
+ constructor(filepath: string, extra?: {
14
+ originalFilename?: string | null;
15
+ newFilename?: string | null;
16
+ });
17
+ hash(hashAlgorithm: 'sha1' | 'md5' | 'sha256'): Promise<{
18
+ algorithm: "sha1" | "sha256" | "md5";
19
+ hash: string | object;
20
+ }>;
21
+ delete(): void;
22
+ move(to: string): void;
23
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NesoiFile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const hash_1 = require("../util/hash");
10
+ const mime_1 = require("../util/mime");
11
+ // Based on [formidable](https://github.com/node-formidable/formidable)
12
+ class NesoiFile {
13
+ constructor(filepath, extra) {
14
+ this.__nesoi_file = true;
15
+ this.hashAlgorithm = false;
16
+ // Only available after `.hash` is called
17
+ this._hash = null;
18
+ this.filepath = filepath;
19
+ this.filename = path_1.default.basename(filepath);
20
+ const mime = mime_1.Mime.ofFilepath(filepath);
21
+ this.extname = extra?.originalFilename
22
+ ? path_1.default.extname(extra.originalFilename).slice(1)
23
+ : mime.extname;
24
+ this.mimetype = mime.mimetype;
25
+ const stat = fs_1.default.statSync(filepath);
26
+ this.size = stat.size;
27
+ this.originalFilename = extra?.originalFilename || null;
28
+ this.newFilename = extra?.newFilename || this.filename;
29
+ this.mtime = stat.mtime;
30
+ }
31
+ async hash(hashAlgorithm) {
32
+ if (!this._hash) {
33
+ this.hashAlgorithm = hashAlgorithm;
34
+ this._hash = hash_1.Hash.file(this.filepath, this.hashAlgorithm).then(hash => {
35
+ this._hash = hash;
36
+ });
37
+ }
38
+ return {
39
+ algorithm: hashAlgorithm,
40
+ hash: this._hash
41
+ };
42
+ }
43
+ delete() {
44
+ if (fs_1.default.existsSync(this.filepath))
45
+ fs_1.default.rmSync(this.filepath);
46
+ }
47
+ move(to) {
48
+ if (fs_1.default.existsSync(this.filepath))
49
+ fs_1.default.renameSync(this.filepath, to);
50
+ this.filepath = to;
51
+ }
52
+ }
53
+ exports.NesoiFile = NesoiFile;
@@ -0,0 +1,6 @@
1
+ export declare class NesoiJSON {
2
+ /**
3
+ * Dumps an object to
4
+ */
5
+ static dump(obj: Record<string, any>): string;
6
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NesoiJSON = void 0;
4
+ const date_1 = require("./date");
5
+ const datetime_1 = require("./datetime");
6
+ const decimal_1 = require("./decimal");
7
+ class NesoiJSON {
8
+ /**
9
+ * Dumps an object to
10
+ */
11
+ static dump(obj) {
12
+ return JSON.stringify(obj, (key, value) => {
13
+ if (value instanceof date_1.NesoiDate) {
14
+ return value.toISO();
15
+ }
16
+ if (value instanceof datetime_1.NesoiDatetime) {
17
+ return value.toISO();
18
+ }
19
+ if (value instanceof decimal_1.NesoiDecimal) {
20
+ return value.toString();
21
+ }
22
+ return value;
23
+ });
24
+ }
25
+ }
26
+ exports.NesoiJSON = NesoiJSON;
@@ -2,7 +2,7 @@ export type NesoiObjId = number | string;
2
2
  export interface NesoiObj {
3
3
  id: NesoiObjId;
4
4
  }
5
- export type NewOrOldObj<T extends NesoiObj> = {
5
+ export type ObjWithOptionalId<T extends NesoiObj> = {
6
6
  id?: T['id'];
7
7
  } & Omit<T, 'id'>;
8
8
  type DefinedKeys<T> = {
@@ -0,0 +1,14 @@
1
+ import { NesoiDatetime } from './datetime';
2
+ export type TrashObj = {
3
+ id: number;
4
+ bucket: string;
5
+ original_id: number | string;
6
+ data: Record<string, any>;
7
+ adapter: {
8
+ name: string;
9
+ [x: string]: any;
10
+ };
11
+ trx: Record<string, any>;
12
+ deleted_by?: number | string;
13
+ deleted_at: NesoiDatetime;
14
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,17 +1,12 @@
1
- type TreeNode<T> = {
2
- path: string;
3
- key: string;
4
- value: T;
5
- };
6
1
  export declare class Tree {
7
2
  /**
8
- * When the fieldpath contains a `.*.`, which refers to a item in a list:
9
- * - If the `index` parameter is null, returns nested lists
10
- * - If the `index` parameter is a list of indices, returns the target object
3
+ * Read one or more values from the object, from a _fieldpath_.
11
4
  *
5
+ * The `index` argument is only relevant if the fieldpath contains a spread (`.#`):
6
+ * - `*`: Return all values of the matched array or dict
7
+ * - `0`: Return the first value of an array or dict (dict ordering is unstable)
8
+ * - `(number|string)[]`: Sequence of values to replace the `#`s on the fieldpath
12
9
  */
13
- static get(obj: Record<string, any>, fieldpath: string, index?: 0 | null | (number | string)[]): any;
14
- static find<P>(obj: Record<string, P>, fn: (path: string, value: P) => boolean, link?: string, _prefix?: string): TreeNode<P> | undefined;
15
- static findAll<P>(obj: Record<string, P>, fn: (path: string, value: P) => boolean, _prefix?: string): TreeNode<P>[];
10
+ static get(obj: Record<string, any>, fieldpath: string, index?: '*' | 0 | (number | string)[]): any;
11
+ static set(obj: Record<string, any>, fieldpath: string, replacer: (v: any, i: (number | string)[]) => any, __index?: (number | string)[]): void;
16
12
  }
17
- export {};