@nymphjs/nymph 1.0.0-beta.46 → 1.0.0-beta.47

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/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-beta.47](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.46...v1.0.0-beta.47) (2023-11-10)
7
+
8
+ **Note:** Version bump only for package @nymphjs/nymph
9
+
6
10
  # [1.0.0-beta.46](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.45...v1.0.0-beta.46) (2023-08-29)
7
11
 
8
12
  **Note:** Version bump only for package @nymphjs/nymph
package/README.md CHANGED
@@ -46,7 +46,7 @@ async function run() {
46
46
 
47
47
  const otherPendingTodos = await nymph.getEntities(
48
48
  { class: Todo },
49
- { type: '&', '!guid': myEntity.guid, equal: ['done', false] }
49
+ { type: '&', '!guid': myEntity.guid, equal: ['done', false] },
50
50
  );
51
51
 
52
52
  const total = otherPendingTodos.length;
@@ -54,7 +54,7 @@ async function run() {
54
54
  console.log(
55
55
  `Besides the one I just created, there ${
56
56
  single ? 'is' : 'are'
57
- } ${total} pending todo${single ? '' : 's'} in the database.`
57
+ } ${total} pending todo${single ? '' : 's'} in the database.`,
58
58
  );
59
59
  }
60
60
  ```
@@ -95,7 +95,7 @@ export default class Todo extends Entity<TodoData> {
95
95
  // instance of Nymph, so it could be a transactional instance.
96
96
  const otherTodos = await this.$nymph.getEntities(
97
97
  { class: Todo },
98
- { type: '!&', guid: this.guid }
98
+ { type: '!&', guid: this.guid },
99
99
  );
100
100
  return otherTodos;
101
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nymphjs/nymph",
3
- "version": "1.0.0-beta.46",
3
+ "version": "1.0.0-beta.47",
4
4
  "description": "Nymph.js - Nymph ORM",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -31,21 +31,21 @@
31
31
  },
32
32
  "license": "Apache-2.0",
33
33
  "dependencies": {
34
- "@nymphjs/guid": "^1.0.0-beta.46",
35
- "joi": "^17.9.2",
34
+ "@nymphjs/guid": "^1.0.0-beta.47",
35
+ "joi": "^17.11.0",
36
36
  "locutus": "^2.0.16",
37
37
  "lodash": "^4.17.21",
38
38
  "n-readlines": "^1.0.3"
39
39
  },
40
40
  "devDependencies": {
41
- "@tsconfig/recommended": "^1.0.2",
42
- "@types/jest": "^29.5.2",
43
- "@types/locutus": "^0.0.6",
44
- "@types/lodash": "^4.14.195",
45
- "@types/n-readlines": "^1.0.3",
46
- "jest": "^29.5.0",
47
- "ts-jest": "^29.1.0",
48
- "typescript": "^5.1.3"
41
+ "@tsconfig/recommended": "^1.0.3",
42
+ "@types/jest": "^29.5.8",
43
+ "@types/locutus": "^0.0.8",
44
+ "@types/lodash": "^4.14.201",
45
+ "@types/n-readlines": "^1.0.6",
46
+ "jest": "^29.7.0",
47
+ "ts-jest": "^29.1.1",
48
+ "typescript": "^5.2.2"
49
49
  },
50
- "gitHead": "25431d66afea7c1a3299b9588afdd79960d82885"
50
+ "gitHead": "228f0d25911d1b98859f2acf8ace3d3f251c4882"
51
51
  }
@@ -142,7 +142,7 @@ describe('Entity', () => {
142
142
  await testEntity.$refresh();
143
143
 
144
144
  expect(testEntityCopy.mdate ?? Infinity).toBeLessThanOrEqual(
145
- testEntity.mdate ?? 0
145
+ testEntity.mdate ?? 0,
146
146
  );
147
147
  });
148
148
 
@@ -162,7 +162,7 @@ describe('Entity', () => {
162
162
  expect(testEntity.$hasTag('test', 'test2')).toEqual(true);
163
163
  testEntity.$addTag('test', 'test3', 'test4', 'test5', 'test6');
164
164
  expect(
165
- testEntity.$hasTag('test', 'test3', 'test4', 'test5', 'test6')
165
+ testEntity.$hasTag('test', 'test3', 'test4', 'test5', 'test6'),
166
166
  ).toEqual(true);
167
167
  testEntity.$removeTag('test2');
168
168
  expect(testEntity.$hasTag('test2')).toEqual(false);
package/src/Entity.ts CHANGED
@@ -249,7 +249,7 @@ export default class Entity<T extends EntityData = EntityData>
249
249
  data[name] = referencesToEntities(
250
250
  JSON.parse(this.$sdata[name]),
251
251
  this.$nymph,
252
- this.$skipAc
252
+ this.$skipAc,
253
253
  );
254
254
  delete this.$sdata[name];
255
255
  }
@@ -284,7 +284,7 @@ export default class Entity<T extends EntityData = EntityData>
284
284
  defineProperty: (
285
285
  data: EntityData,
286
286
  name: string,
287
- descriptor: PropertyDescriptor
287
+ descriptor: PropertyDescriptor,
288
288
  ) => {
289
289
  this.$check();
290
290
 
@@ -302,7 +302,7 @@ export default class Entity<T extends EntityData = EntityData>
302
302
  data[name] = referencesToEntities(
303
303
  JSON.parse(this.$sdata[name]),
304
304
  this.$nymph,
305
- this.$skipAc
305
+ this.$skipAc,
306
306
  );
307
307
  delete this.$sdata[name];
308
308
  }
@@ -313,7 +313,7 @@ export default class Entity<T extends EntityData = EntityData>
313
313
  this.$check();
314
314
 
315
315
  return Object.getOwnPropertyNames(data).concat(
316
- Object.getOwnPropertyNames(this.$sdata)
316
+ Object.getOwnPropertyNames(this.$sdata),
317
317
  );
318
318
  },
319
319
  };
@@ -389,7 +389,7 @@ export default class Entity<T extends EntityData = EntityData>
389
389
  defineProperty: (
390
390
  entity: Entity,
391
391
  name: string,
392
- descriptor: PropertyDescriptor
392
+ descriptor: PropertyDescriptor,
393
393
  ) => {
394
394
  if (
395
395
  typeof name !== 'string' ||
@@ -426,7 +426,7 @@ export default class Entity<T extends EntityData = EntityData>
426
426
  ownKeys: (entity: Entity) => {
427
427
  this.$check();
428
428
  return Object.getOwnPropertyNames(entity).concat(
429
- Object.getOwnPropertyNames(entity.$data)
429
+ Object.getOwnPropertyNames(entity.$data),
430
430
  );
431
431
  },
432
432
  }) as Entity<T>;
@@ -439,7 +439,7 @@ export default class Entity<T extends EntityData = EntityData>
439
439
  {
440
440
  class: this as any as EntityConstructor,
441
441
  },
442
- { type: '&', guid }
442
+ { type: '&', guid },
443
443
  );
444
444
  if (entity != null) {
445
445
  return entity;
@@ -676,7 +676,7 @@ export default class Entity<T extends EntityData = EntityData>
676
676
 
677
677
  if (this.guid != input.guid) {
678
678
  throw new EntityConflictError(
679
- 'Tried to accept JSON input for the wrong entity.'
679
+ 'Tried to accept JSON input for the wrong entity.',
680
680
  );
681
681
  }
682
682
 
@@ -726,10 +726,10 @@ export default class Entity<T extends EntityData = EntityData>
726
726
  (this.constructor as typeof Entity).class !== 'Group') ||
727
727
  !(this.$nymph.tilmeld as any).currentUser ||
728
728
  (!(this.$nymph.tilmeld as any).currentUser.abilities?.includes(
729
- 'tilmeld/admin'
729
+ 'tilmeld/admin',
730
730
  ) &&
731
731
  !(this.$nymph.tilmeld as any).currentUser.abilities?.includes(
732
- 'system/admin'
732
+ 'system/admin',
733
733
  ))
734
734
  ) {
735
735
  protectedProps.push('user');
@@ -771,7 +771,7 @@ export default class Entity<T extends EntityData = EntityData>
771
771
 
772
772
  if (this.guid != patch.guid) {
773
773
  throw new EntityConflictError(
774
- 'Tried to accept JSON patch for the wrong entity.'
774
+ 'Tried to accept JSON patch for the wrong entity.',
775
775
  );
776
776
  }
777
777
 
@@ -796,10 +796,10 @@ export default class Entity<T extends EntityData = EntityData>
796
796
  (this.constructor as typeof Entity).class !== 'Group') ||
797
797
  !(this.$nymph.tilmeld as any).currentUser ||
798
798
  (!(this.$nymph.tilmeld as any).currentUser.abilities?.includes(
799
- 'tilmeld/admin'
799
+ 'tilmeld/admin',
800
800
  ) &&
801
801
  !(this.$nymph.tilmeld as any).currentUser.abilities?.includes(
802
- 'system/admin'
802
+ 'system/admin',
803
803
  ))
804
804
  ) {
805
805
  protectedProps.push('user');
@@ -819,7 +819,7 @@ export default class Entity<T extends EntityData = EntityData>
819
819
  (this.$data as any)[name] = referencesToEntities(
820
820
  patch.set[name],
821
821
  this.$nymph,
822
- this.$skipAc
822
+ this.$skipAc,
823
823
  );
824
824
  }
825
825
 
@@ -872,7 +872,7 @@ export default class Entity<T extends EntityData = EntityData>
872
872
  (this.$dataStore as any)[name] = referencesToEntities(
873
873
  data[name],
874
874
  this.$nymph,
875
- this.$skipAc
875
+ this.$skipAc,
876
876
  );
877
877
  }
878
878
  this.$sdata = mySdata;
@@ -895,14 +895,14 @@ export default class Entity<T extends EntityData = EntityData>
895
895
  ) {
896
896
  throw new InvalidParametersError(
897
897
  'referenceSleep expects parameter 1 to be a valid Nymph entity ' +
898
- 'reference.'
898
+ 'reference.',
899
899
  );
900
900
  }
901
901
  const thisClass: string = (this.constructor as any).class;
902
902
  if (reference[2] !== thisClass) {
903
903
  throw new InvalidParametersError(
904
904
  'referenceSleep can only be called with an entity reference of the ' +
905
- `same class. Given class: ${reference[2]}; this class: ${thisClass}.`
905
+ `same class. Given class: ${reference[2]}; this class: ${thisClass}.`,
906
906
  );
907
907
  }
908
908
  this.$isASleepingReference = true;
@@ -916,7 +916,7 @@ export default class Entity<T extends EntityData = EntityData>
916
916
  protected $check() {
917
917
  if (this.$isASleepingReference || this.$sleepingReference != null) {
918
918
  throw new EntityIsSleepingReferenceError(
919
- 'This entity is in a sleeping reference state. You must use .$wake() to wake it.'
919
+ 'This entity is in a sleeping reference state. You must use .$wake() to wake it.',
920
920
  );
921
921
  }
922
922
  }
@@ -938,12 +938,12 @@ export default class Entity<T extends EntityData = EntityData>
938
938
  }
939
939
  if (this.$sleepingReference?.[1] == null) {
940
940
  throw new InvalidStateError(
941
- 'Tried to wake a sleeping reference with no GUID.'
941
+ 'Tried to wake a sleeping reference with no GUID.',
942
942
  );
943
943
  }
944
944
  if (!this.$wakePromise) {
945
945
  const EntityClass = this.$nymph.getEntityClass(
946
- this.$sleepingReference[2]
946
+ this.$sleepingReference[2],
947
947
  );
948
948
  this.$wakePromise = this.$nymph
949
949
  .getEntity(
@@ -951,14 +951,14 @@ export default class Entity<T extends EntityData = EntityData>
951
951
  class: EntityClass,
952
952
  skipAc: this.$skipAc,
953
953
  },
954
- { type: '&', guid: this.$sleepingReference[1] }
954
+ { type: '&', guid: this.$sleepingReference[1] },
955
955
  )
956
956
  .then((entity) => {
957
957
  if (entity == null || entity.guid == null) {
958
958
  return Promise.reject(
959
959
  new InvalidStateError(
960
- 'The sleeping reference could not be retrieved.'
961
- )
960
+ 'The sleeping reference could not be retrieved.',
961
+ ),
962
962
  );
963
963
  }
964
964
  this.$isASleepingReference = false;
@@ -1011,7 +1011,7 @@ export default class Entity<T extends EntityData = EntityData>
1011
1011
  if (promises.length) {
1012
1012
  Promise.all(promises).then(
1013
1013
  () => resolve(this),
1014
- (errObj) => reject(errObj)
1014
+ (errObj) => reject(errObj),
1015
1015
  );
1016
1016
  } else {
1017
1017
  resolve(this);
@@ -1035,12 +1035,12 @@ export default class Entity<T extends EntityData = EntityData>
1035
1035
  const refresh = await this.$nymph.getEntity(
1036
1036
  {
1037
1037
  class: this.$nymph.getEntityClass(
1038
- this.constructor as EntityConstructor
1038
+ this.constructor as EntityConstructor,
1039
1039
  ),
1040
1040
  skipCache: true,
1041
1041
  skipAc: this.$skipAc,
1042
1042
  },
1043
- { type: '&', guid: this.guid }
1043
+ { type: '&', guid: this.guid },
1044
1044
  );
1045
1045
  if (refresh == null) {
1046
1046
  return 0;
package/src/Nymph.ts CHANGED
@@ -138,7 +138,7 @@ export default class Nymph {
138
138
  config: Partial<Config>,
139
139
  driver: NymphDriver,
140
140
  tilmeld?: TilmeldInterface,
141
- parent?: Nymph
141
+ parent?: Nymph,
142
142
  ) {
143
143
  this.config = { ...defaults, ...config };
144
144
  this.driver = driver;
@@ -244,7 +244,7 @@ export default class Nymph {
244
244
  public getEntityClass<T extends EntityConstructor>(className: T): T;
245
245
  public getEntityClass(className: string): EntityConstructor;
246
246
  public getEntityClass<T extends EntityConstructor = EntityConstructor>(
247
- className: T | string
247
+ className: T | string,
248
248
  ): T | EntityConstructor {
249
249
  let key: string | null = null;
250
250
  if (typeof className === 'string') {
@@ -268,7 +268,7 @@ export default class Nymph {
268
268
  this.config,
269
269
  this.driver.clone(),
270
270
  this.tilmeld?.clone(),
271
- this
271
+ this,
272
272
  );
273
273
  }
274
274
 
@@ -791,11 +791,11 @@ export default class Nymph {
791
791
  ): Promise<ReturnType<T['factorySync']> | null>;
792
792
  public async getEntity<T extends EntityConstructor = EntityConstructor>(
793
793
  options: Options<T> & { return: 'guid' },
794
- guid: string
794
+ guid: string,
795
795
  ): Promise<string | null>;
796
796
  public async getEntity<T extends EntityConstructor = EntityConstructor>(
797
797
  options: Options<T>,
798
- guid: string
798
+ guid: string,
799
799
  ): Promise<ReturnType<T['factorySync']> | null>;
800
800
  public async getEntity<T extends EntityConstructor = EntityConstructor>(
801
801
  options: Options<T> = {},
@@ -813,7 +813,7 @@ export default class Nymph {
813
813
  }
814
814
  const entities = await this.driver.getEntities(
815
815
  options,
816
- ...(selectors as Selector[])
816
+ ...(selectors as Selector[]),
817
817
  );
818
818
  if (options.return === 'count') {
819
819
  return entities as unknown as number;
@@ -864,7 +864,7 @@ export default class Nymph {
864
864
  */
865
865
  public async deleteEntityByID(
866
866
  guid: string,
867
- className?: string
867
+ className?: string,
868
868
  ): Promise<boolean> {
869
869
  for (let callback of this.beforeDeleteEntityByIDCallbacks) {
870
870
  if (callback) {
@@ -1015,7 +1015,7 @@ export default class Nymph {
1015
1015
  ? NymphBeforeRollbackTransactionCallback
1016
1016
  : T extends 'afterRollbackTransaction'
1017
1017
  ? NymphAfterRollbackTransactionCallback
1018
- : never
1018
+ : never,
1019
1019
  ) {
1020
1020
  const prop = (event + 'Callbacks') as T extends 'connect'
1021
1021
  ? 'connectCallbacks'
@@ -1156,7 +1156,7 @@ export default class Nymph {
1156
1156
  ? NymphBeforeRollbackTransactionCallback
1157
1157
  : T extends 'afterRollbackTransaction'
1158
1158
  ? NymphAfterRollbackTransactionCallback
1159
- : never
1159
+ : never,
1160
1160
  ) {
1161
1161
  const prop = (event + 'Callbacks') as T extends 'connect'
1162
1162
  ? 'connectCallbacks'
@@ -36,11 +36,11 @@ export type NymphEventType =
36
36
  | 'afterRollbackTransaction';
37
37
  export type NymphConnectCallback = (
38
38
  nymph: Nymph,
39
- result: Promise<boolean>
39
+ result: Promise<boolean>,
40
40
  ) => Promise<void>;
41
41
  export type NymphDisconnectCallback = (
42
42
  nymph: Nymph,
43
- result: Promise<boolean>
43
+ result: Promise<boolean>,
44
44
  ) => Promise<void>;
45
45
  /**
46
46
  * The NymphQueryCallback will be called on both top level and qref queries.
@@ -56,131 +56,131 @@ export type NymphDisconnectCallback = (
56
56
  export type NymphQueryCallback = (
57
57
  nymph: Nymph,
58
58
  options: Options,
59
- selectors: FormattedSelector[]
59
+ selectors: FormattedSelector[],
60
60
  ) => void;
61
61
  export type NymphBeforeGetEntityCallback = (
62
62
  nymph: Nymph,
63
63
  options: Options,
64
- selectors: Selector[]
64
+ selectors: Selector[],
65
65
  ) => Promise<void>;
66
66
  export type NymphBeforeGetEntitiesCallback = (
67
67
  nymph: Nymph,
68
68
  options: Options,
69
- selectors: Selector[]
69
+ selectors: Selector[],
70
70
  ) => Promise<void>;
71
71
  export type NymphBeforeSaveEntityCallback = (
72
72
  nymph: Nymph,
73
- entity: EntityInterface
73
+ entity: EntityInterface,
74
74
  ) => Promise<void>;
75
75
  export type NymphAfterSaveEntityCallback = (
76
76
  nymph: Nymph,
77
- result: Promise<boolean>
77
+ result: Promise<boolean>,
78
78
  ) => Promise<void>;
79
79
  export type NymphFailedSaveEntityCallback = (
80
80
  nymph: Nymph,
81
- error: any
81
+ error: any,
82
82
  ) => Promise<void>;
83
83
  export type NymphBeforeDeleteEntityCallback = (
84
84
  nymph: Nymph,
85
- entity: EntityInterface
85
+ entity: EntityInterface,
86
86
  ) => Promise<void>;
87
87
  export type NymphAfterDeleteEntityCallback = (
88
88
  nymph: Nymph,
89
- result: Promise<boolean>
89
+ result: Promise<boolean>,
90
90
  ) => Promise<void>;
91
91
  export type NymphFailedDeleteEntityCallback = (
92
92
  nymph: Nymph,
93
- error: any
93
+ error: any,
94
94
  ) => Promise<void>;
95
95
  export type NymphBeforeDeleteEntityByIDCallback = (
96
96
  nymph: Nymph,
97
97
  guid: string,
98
- className?: string
98
+ className?: string,
99
99
  ) => Promise<void>;
100
100
  export type NymphAfterDeleteEntityByIDCallback = (
101
101
  nymph: Nymph,
102
- result: Promise<boolean>
102
+ result: Promise<boolean>,
103
103
  ) => Promise<void>;
104
104
  export type NymphFailedDeleteEntityByIDCallback = (
105
105
  nymph: Nymph,
106
- error: any
106
+ error: any,
107
107
  ) => Promise<void>;
108
108
  export type NymphBeforeNewUIDCallback = (
109
109
  nymph: Nymph,
110
- name: string
110
+ name: string,
111
111
  ) => Promise<void>;
112
112
  export type NymphAfterNewUIDCallback = (
113
113
  nymph: Nymph,
114
- result: Promise<number | null>
114
+ result: Promise<number | null>,
115
115
  ) => Promise<void>;
116
116
  export type NymphFailedNewUIDCallback = (
117
117
  nymph: Nymph,
118
- error: any
118
+ error: any,
119
119
  ) => Promise<void>;
120
120
  export type NymphBeforeSetUIDCallback = (
121
121
  nymph: Nymph,
122
122
  name: string,
123
- value: number
123
+ value: number,
124
124
  ) => Promise<void>;
125
125
  export type NymphAfterSetUIDCallback = (
126
126
  nymph: Nymph,
127
- result: Promise<boolean>
127
+ result: Promise<boolean>,
128
128
  ) => Promise<void>;
129
129
  export type NymphFailedSetUIDCallback = (
130
130
  nymph: Nymph,
131
- error: any
131
+ error: any,
132
132
  ) => Promise<void>;
133
133
  export type NymphBeforeRenameUIDCallback = (
134
134
  nymph: Nymph,
135
135
  oldName: string,
136
- newName: string
136
+ newName: string,
137
137
  ) => Promise<void>;
138
138
  export type NymphAfterRenameUIDCallback = (
139
139
  nymph: Nymph,
140
- result: Promise<boolean>
140
+ result: Promise<boolean>,
141
141
  ) => Promise<void>;
142
142
  export type NymphFailedRenameUIDCallback = (
143
143
  nymph: Nymph,
144
- error: any
144
+ error: any,
145
145
  ) => Promise<void>;
146
146
  export type NymphBeforeDeleteUIDCallback = (
147
147
  nymph: Nymph,
148
- name: string
148
+ name: string,
149
149
  ) => Promise<void>;
150
150
  export type NymphAfterDeleteUIDCallback = (
151
151
  nymph: Nymph,
152
- result: Promise<boolean>
152
+ result: Promise<boolean>,
153
153
  ) => Promise<void>;
154
154
  export type NymphFailedDeleteUIDCallback = (
155
155
  nymph: Nymph,
156
- error: any
156
+ error: any,
157
157
  ) => Promise<void>;
158
158
  export type NymphBeforeStartTransactionCallback = (
159
159
  nymph: Nymph,
160
- name: string
160
+ name: string,
161
161
  ) => Promise<void>;
162
162
  export type NymphAfterStartTransactionCallback = (
163
163
  nymph: Nymph,
164
164
  name: string,
165
- result: Nymph
165
+ result: Nymph,
166
166
  ) => Promise<void>;
167
167
  export type NymphBeforeCommitTransactionCallback = (
168
168
  nymph: Nymph,
169
- name: string
169
+ name: string,
170
170
  ) => Promise<void>;
171
171
  export type NymphAfterCommitTransactionCallback = (
172
172
  nymph: Nymph,
173
173
  name: string,
174
- result: boolean
174
+ result: boolean,
175
175
  ) => Promise<void>;
176
176
  export type NymphBeforeRollbackTransactionCallback = (
177
177
  nymph: Nymph,
178
- name: string
178
+ name: string,
179
179
  ) => Promise<void>;
180
180
  export type NymphAfterRollbackTransactionCallback = (
181
181
  nymph: Nymph,
182
182
  name: string,
183
- result: boolean
183
+ result: boolean,
184
184
  ) => Promise<void>;
185
185
 
186
186
  export type Options<T extends EntityConstructor = EntityConstructor> = {
@@ -383,6 +383,6 @@ export interface TilmeldInterface {
383
383
  fillSession(user: any): Promise<void>;
384
384
  checkClientUIDPermissions(
385
385
  name: string,
386
- type?: TilmeldAccessLevels
386
+ type?: TilmeldAccessLevels,
387
387
  ): Promise<boolean>;
388
388
  }