nesoi 3.2.2 → 3.2.4

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.
@@ -2,7 +2,6 @@ import { $Module, $Space } from "../../../../schema";
2
2
  import { $BucketModelField, $BucketModelFieldType, $BucketModelFields } from './bucket_model.schema';
3
3
  import { NesoiDate } from "../../../../engine/data/date";
4
4
  import { BucketModelpathObjInfer, BucketModelpathDictInfer, BucketModelpathListInfer, BucketModelObjInfer, BucketQuerypathDictInfer, BucketQuerypathListInfer, BucketQuerypathObjInfer, BucketModelpathUnionInfer } from './bucket_model.infer';
5
- import { EnumFromName, EnumName } from '../../constants/constants.schema';
6
5
  import { NesoiDecimal } from "../../../../engine/data/decimal";
7
6
  import { NesoiDatetime } from "../../../../engine/data/datetime";
8
7
  import { NesoiFile } from "../../../../engine/data/file";
@@ -49,10 +48,10 @@ export declare class BucketModelFieldFactory<Space extends $Space, Module extend
49
48
  }, {
50
49
  '': NesoiDecimal;
51
50
  }>;
52
- enum<Enums extends EnumName<Space>, Options extends (keyof Enums & string) | (readonly string[])>(options: Options): BucketModelFieldBuilder<Module, Options extends string ? keyof EnumFromName<Space, Options>["#data"] : Options extends (infer X)[] | readonly (infer X)[] ? X : Options[keyof Options], Options extends string ? keyof EnumFromName<Space, Options>["#data"] : Options extends (infer X)[] | readonly (infer X)[] ? X : Options[keyof Options], [false, false], {
53
- '': Options extends string ? keyof EnumFromName<Space, Options>["#data"] : Options extends (infer X)[] | readonly (infer X)[] ? X : Options[keyof Options];
51
+ enum<Enums extends Module['constants']['enums'], Options extends (keyof Enums & string) | (readonly string[])>(options: Options): BucketModelFieldBuilder<Module, Options extends string ? keyof Module["constants"]["enums"][Options]["#data"] : Options extends (infer X)[] | readonly (infer X)[] ? X : Options[keyof Options], Options extends string ? keyof Module["constants"]["enums"][Options]["#data"] : Options extends (infer X)[] | readonly (infer X)[] ? X : Options[keyof Options], [false, false], {
52
+ '': Options extends string ? keyof Module["constants"]["enums"][Options]["#data"] : Options extends (infer X)[] | readonly (infer X)[] ? X : Options[keyof Options];
54
53
  }, {
55
- '': Options extends string ? keyof EnumFromName<Space, Options>["#data"] : Options extends (infer X)[] | readonly (infer X)[] ? X : Options[keyof Options];
54
+ '': Options extends string ? keyof Module["constants"]["enums"][Options]["#data"] : Options extends (infer X)[] | readonly (infer X)[] ? X : Options[keyof Options];
56
55
  }>;
57
56
  get int(): BucketModelFieldBuilder<Module, number, number, [false, false], {
58
57
  '': number;
@@ -91,6 +91,8 @@ class NQL_RuleTree {
91
91
  let by = value['by'];
92
92
  if (by) {
93
93
  for (const key of by) {
94
+ if (Object.values(bucket.adapter.config.meta).includes(key))
95
+ continue;
94
96
  const fields = bucket_model_schema_1.$BucketModel.getField(bucket.schema.model, key);
95
97
  if (!fields.length) {
96
98
  throw new Error(`Field '${key}' not found on bucket '${bucket.schema.name}'`);
@@ -148,6 +150,10 @@ class NQL_RuleTree {
148
150
  throw new Error(`Invalid term '${key}'`);
149
151
  }
150
152
  const [_, or, fieldpath, not, case_i, op] = term;
153
+ if (Object.values(bucket.adapter.config.meta).includes(fieldpath)) {
154
+ const _op = this.parseOp(bucket.schema.name, [{ type: 'datetime', name: fieldpath }], op);
155
+ return { type: 'fieldpath', or: !!or, fieldpath, not: !!not, case_i: !!case_i, op: _op };
156
+ }
151
157
  const fields = bucket_model_schema_1.$BucketModel.getField(bucket.schema.model, fieldpath);
152
158
  if (!fields.length) {
153
159
  throw new Error(`Field '${fieldpath}' not found on bucket '${bucket.schema.name}'`);
@@ -242,7 +248,7 @@ class NQL_RuleTree {
242
248
  };
243
249
  for (const key in value) {
244
250
  if (key.startsWith('@') || key.startsWith('or @')) {
245
- const refField = key.match(/(or )?@(\w+)\.(.*)/);
251
+ const refField = key.match(/(or )?@([\w:]+)\.(.*)/);
246
252
  if (!refField) {
247
253
  throw new Error(`Invalid bucket field '${key}'`);
248
254
  }
@@ -54,10 +54,8 @@ type CompatibleMessageKey<Data, Subs extends string> = {
54
54
  }[keyof Data];
55
55
  type ParseMessageEnumpath<Message extends $Message, Path extends string, Subs extends string> = Path extends `${infer X}.#` ? `${X}.{${CompatibleMessageKey<Message['#parsed'], Subs> & string}}` : Path;
56
56
  export type MessageEnumpath<Module extends $Module, Message extends $Message, Modules extends Record<string, $Module>> = MergeUnion<{
57
- [M in keyof Modules]: {
58
- [K in keyof Modules[M]['constants']['#enumpath'] as M extends Module['name'] ? ParseMessageEnumpath<Message, K & string, Modules[M]['constants']['#enumpath'][K]['_subs']> : `${M & string}::${ParseMessageEnumpath<Message, K & string, Modules[M]['constants']['#enumpath'][K]['_subs']>}`]: Modules[M]['constants']['#enumpath'][K]['_enum'];
59
- };
60
- }[keyof Modules]>;
57
+ [K in keyof Module['constants']['#enumpath'] as ParseMessageEnumpath<Message, K & string, Module['constants']['#enumpath'][K]['_subs']>]: Module['constants']['#enumpath'][K]['_enum'];
58
+ }>;
61
59
  export type EnumName<Space extends $Space> = MergeUnion<{
62
60
  [M in keyof Space['modules']]: {
63
61
  [K in keyof Space['modules'][M]['constants']['enums'] as `${M & string}::${K & string}`]: Space['modules'][M]['constants']['enums'][K];
@@ -127,6 +127,7 @@ class InlineApp extends app_1.App {
127
127
  messages: Object.values(module.schema.externals.messages),
128
128
  jobs: Object.values(module.schema.externals.jobs),
129
129
  machines: Object.values(module.schema.externals.machines),
130
+ enums: Object.values(module.schema.externals.enums)
130
131
  });
131
132
  const buckets = module.schema.externals.buckets;
132
133
  Object.values(buckets).forEach(bucket => {
@@ -133,8 +133,7 @@ export declare class Module<S extends $Space, $ extends $Module> {
133
133
  }): this;
134
134
  /**
135
135
  * Include references for external elements on the module.
136
- * This allows a module to use elements from other modules directly,
137
- * on single-threaded `Apps`.
136
+ * This allows a module to use elements from other modules directly.
138
137
  * This implementation also includes transitive dependencies.
139
138
  *
140
139
  * @param daemon A `Daemon` instance
@@ -146,6 +145,7 @@ export declare class Module<S extends $Space, $ extends $Module> {
146
145
  jobs?: $Dependency[];
147
146
  messages?: $Dependency[];
148
147
  machines?: $Dependency[];
148
+ enums?: $Dependency[];
149
149
  }): this;
150
150
  /**
151
151
  * Include references for external elements on the module.
@@ -171,8 +171,7 @@ class Module {
171
171
  }
172
172
  /**
173
173
  * Include references for external elements on the module.
174
- * This allows a module to use elements from other modules directly,
175
- * on single-threaded `Apps`.
174
+ * This allows a module to use elements from other modules directly.
176
175
  * This implementation also includes transitive dependencies.
177
176
  *
178
177
  * @param daemon A `Daemon` instance
@@ -222,6 +221,14 @@ class Module {
222
221
  jobs: schema.jobs
223
222
  });
224
223
  });
224
+ dependencies.enums?.forEach(dep => {
225
+ const enumModule = modules[dep.module];
226
+ const _enum = enumModule.schema.constants.enums[dep.name];
227
+ if (!_enum) {
228
+ throw new Error(`Internal Error: unable to find enum '${dep.refName}' during injection to module '${this.name}'`);
229
+ }
230
+ this.schema.constants.enums[`${dep.refName}`] = _enum;
231
+ });
225
232
  return this;
226
233
  }
227
234
  /**
@@ -17,7 +17,7 @@ export declare class BucketQueryTrxNode<M extends $Module, B extends $Bucket, V
17
17
  private _params?;
18
18
  constructor(trx: TrxNode<any, M, any>, bucket: Bucket<M, B>, query: NQL_AnyQuery, enableTenancy: boolean, view?: V | undefined);
19
19
  merge($: NQL_Query<M, B>): void;
20
- params(value: Record<string, any>): this;
20
+ params(value?: Record<string, any>): this;
21
21
  first(): Promise<Obj | undefined>;
22
22
  firstOrFail(): Promise<Obj>;
23
23
  all(): Promise<Obj[]>;
@@ -26,7 +26,7 @@ class BucketQueryTrxNode {
26
26
  this.query['#or*'] = or; // TODO: make this a little better
27
27
  }
28
28
  params(value) {
29
- this._params = [value];
29
+ this._params = value ? [value] : [];
30
30
  return this;
31
31
  }
32
32
  async first() {
@@ -10,7 +10,6 @@ import { $Message } from "../../elements/entities/message/message.schema";
10
10
  import { MachineTrxNode } from './nodes/machine.trx_node';
11
11
  import { AnyUsers, AuthnRequest } from '../auth/authn';
12
12
  import { Enum } from "../../elements/entities/constants/constants";
13
- import { KeysOfUnion } from '../util/type';
14
13
  import { TopicTrxNode } from './nodes/topic.trx_node';
15
14
  type TrxNodeBlock = 'bucket' | 'message' | 'job' | 'resource' | 'machine' | 'queue' | 'topic' | 'controller';
16
15
  export type TrxNodeStatus = {
@@ -52,7 +51,7 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
52
51
  static error(node: AnyTrxNode, error: any): Promise<any>;
53
52
  message<Raw extends M['#input']['#raw'], Msg extends $Message = M['messages'][Raw['$'] & keyof M['messages']]>(raw: Raw): Promise<M['#input']['#parsed']>;
54
53
  value<K extends keyof M['constants']['values']>(key: K): M["constants"]["values"][K]["value"];
55
- enum<EnumName extends KeysOfUnion<Space['modules'][keyof Space['modules']]['constants']['enums']>>(name: EnumName): Enum<M['constants']['enums'][EnumName]>;
54
+ enum<EnumName extends keyof M['constants']['enums']>(name: EnumName): Enum<M['constants']['enums'][EnumName]>;
56
55
  bucket<Name extends keyof M['buckets'], Bucket extends M['buckets'][Name]>(name: Name): BucketTrxNode<M, Bucket>;
57
56
  job<Name extends keyof M['jobs'], Job extends M['jobs'][Name]>(name: Name): JobTrxNode<M, Job>;
58
57
  static jobWithCustomCtx<M extends $Module, JobName extends keyof M['jobs'], Job extends M['jobs'][JobName]>(node: AnyTrxNode, name: string, ctx?: Record<string, any>): JobTrxNode<M, Job>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesoi",
3
- "version": "3.2.2",
3
+ "version": "3.2.4",
4
4
  "description": "Declarative framework for data-driven applications",
5
5
  "repository": {
6
6
  "type": "git",