@nymphjs/nymph 1.0.0-beta.11 → 1.0.0-beta.111

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 (103) hide show
  1. package/CHANGELOG.md +540 -0
  2. package/README.md +23 -21
  3. package/dist/Entity.d.ts +293 -10
  4. package/dist/Entity.js +560 -148
  5. package/dist/Entity.js.map +1 -1
  6. package/dist/Entity.test.js +52 -13
  7. package/dist/Entity.test.js.map +1 -1
  8. package/dist/Entity.types.d.ts +256 -23
  9. package/dist/Entity.types.js +1 -2
  10. package/dist/Nymph.d.ts +586 -12
  11. package/dist/Nymph.js +844 -179
  12. package/dist/Nymph.js.map +1 -1
  13. package/dist/Nymph.types.d.ts +81 -8
  14. package/dist/Nymph.types.js +3 -5
  15. package/dist/Nymph.types.js.map +1 -1
  16. package/dist/conf/d.d.ts +43 -0
  17. package/dist/conf/d.js +1 -2
  18. package/dist/conf/defaults.d.ts +1 -1
  19. package/dist/conf/defaults.js +26 -3
  20. package/dist/conf/defaults.js.map +1 -1
  21. package/dist/conf/index.d.ts +2 -2
  22. package/dist/conf/index.js +2 -8
  23. package/dist/conf/index.js.map +1 -1
  24. package/dist/driver/NymphDriver.d.ts +201 -40
  25. package/dist/driver/NymphDriver.js +685 -239
  26. package/dist/driver/NymphDriver.js.map +1 -1
  27. package/dist/driver/index.d.ts +2 -2
  28. package/dist/driver/index.js +3 -23
  29. package/dist/driver/index.js.map +1 -1
  30. package/dist/driver/testArtifacts.d.ts +2 -2
  31. package/dist/driver/testArtifacts.js +909 -93
  32. package/dist/driver/testArtifacts.js.map +1 -1
  33. package/dist/errors/ClassNotAvailableError.js +1 -5
  34. package/dist/errors/ClassNotAvailableError.js.map +1 -1
  35. package/dist/errors/EntityConflictError.js +1 -5
  36. package/dist/errors/EntityConflictError.js.map +1 -1
  37. package/dist/errors/EntityInvalidDataError.d.ts +6 -0
  38. package/dist/errors/EntityInvalidDataError.js +8 -6
  39. package/dist/errors/EntityInvalidDataError.js.map +1 -1
  40. package/dist/errors/EntityIsSleepingReferenceError.js +1 -5
  41. package/dist/errors/EntityIsSleepingReferenceError.js.map +1 -1
  42. package/dist/errors/EntityUniqueConstraintError.d.ts +3 -0
  43. package/dist/errors/EntityUniqueConstraintError.js +7 -0
  44. package/dist/errors/EntityUniqueConstraintError.js.map +1 -0
  45. package/dist/errors/HttpError.d.ts +5 -0
  46. package/dist/errors/HttpError.js +11 -0
  47. package/dist/errors/HttpError.js.map +1 -0
  48. package/dist/errors/InvalidParametersError.js +1 -5
  49. package/dist/errors/InvalidParametersError.js.map +1 -1
  50. package/dist/errors/InvalidStateError.d.ts +3 -0
  51. package/dist/errors/InvalidStateError.js +7 -0
  52. package/dist/errors/InvalidStateError.js.map +1 -0
  53. package/dist/errors/NotConfiguredError.js +1 -5
  54. package/dist/errors/NotConfiguredError.js.map +1 -1
  55. package/dist/errors/QueryFailedError.d.ts +2 -1
  56. package/dist/errors/QueryFailedError.js +5 -6
  57. package/dist/errors/QueryFailedError.js.map +1 -1
  58. package/dist/errors/UnableToConnectError.js +1 -5
  59. package/dist/errors/UnableToConnectError.js.map +1 -1
  60. package/dist/errors/index.d.ts +11 -8
  61. package/dist/errors/index.js +11 -24
  62. package/dist/errors/index.js.map +1 -1
  63. package/dist/index.d.ts +11 -11
  64. package/dist/index.js +14 -34
  65. package/dist/index.js.map +1 -1
  66. package/dist/nymphJoiProps.d.ts +1 -1
  67. package/dist/nymphJoiProps.js +10 -15
  68. package/dist/nymphJoiProps.js.map +1 -1
  69. package/dist/testArtifacts.d.ts +19 -6
  70. package/dist/testArtifacts.js +32 -37
  71. package/dist/testArtifacts.js.map +1 -1
  72. package/dist/testMocks.d.ts +27 -12
  73. package/dist/testMocks.js +40 -29
  74. package/dist/testMocks.js.map +1 -1
  75. package/dist/utils.d.ts +4 -4
  76. package/dist/utils.js +40 -29
  77. package/dist/utils.js.map +1 -1
  78. package/jest.config.js +11 -2
  79. package/package.json +24 -20
  80. package/src/Entity.test.ts +50 -7
  81. package/src/Entity.ts +489 -150
  82. package/src/Entity.types.ts +72 -74
  83. package/src/Nymph.ts +985 -322
  84. package/src/Nymph.types.ts +150 -27
  85. package/src/conf/d.ts +25 -0
  86. package/src/conf/defaults.ts +34 -1
  87. package/src/conf/index.ts +2 -2
  88. package/src/driver/NymphDriver.ts +859 -412
  89. package/src/driver/index.ts +2 -2
  90. package/src/driver/testArtifacts.ts +1090 -186
  91. package/src/errors/EntityUniqueConstraintError.ts +6 -0
  92. package/src/errors/HttpError.ts +12 -0
  93. package/src/errors/InvalidStateError.ts +6 -0
  94. package/src/errors/QueryFailedError.ts +3 -1
  95. package/src/errors/index.ts +14 -8
  96. package/src/index.ts +11 -11
  97. package/src/nymphJoiProps.ts +2 -2
  98. package/src/testArtifacts.ts +20 -20
  99. package/src/testMocks.ts +76 -35
  100. package/src/type/locutus.d.ts +3 -0
  101. package/src/utils.ts +39 -18
  102. package/tsconfig.json +5 -3
  103. package/typedoc.json +4 -0
@@ -1,8 +1,17 @@
1
- import type Nymph from '../Nymph';
2
- import { EntityConstructor, EntityData, EntityInterface, EntityReference, SerializedEntityData } from '../Entity.types';
3
- import { Selector, Options, FormattedSelector } from '../Nymph.types';
1
+ import { Tokenizer } from '@sciactive/tokenizer';
2
+ import type Nymph from '../Nymph.js';
3
+ import type { Selector, Options, FormattedSelector } from '../Nymph.types.js';
4
+ import type { EntityInstanceType, EntityObjectType } from '../Entity.js';
5
+ import type { EntityConstructor, EntityData, EntityInterface, EntityReference, SerializedEntityData } from '../Entity.types.js';
6
+ /**
7
+ * A Nymph database driver.
8
+ */
4
9
  export default abstract class NymphDriver {
5
10
  protected nymph: Nymph;
11
+ protected tokenizer: Tokenizer;
12
+ /**
13
+ * A cache to make entity retrieval faster.
14
+ */
6
15
  protected entityCache: {
7
16
  [k: string]: {
8
17
  cdate: number;
@@ -12,13 +21,28 @@ export default abstract class NymphDriver {
12
21
  sdata: SerializedEntityData;
13
22
  };
14
23
  };
24
+ /**
25
+ * A counter for the entity cache to determine the most accessed entities.
26
+ */
15
27
  protected entityCount: {
16
28
  [k: string]: number;
17
29
  };
30
+ /**
31
+ * Protect against infinite loops.
32
+ */
18
33
  private putDataCounter;
34
+ /**
35
+ * This is used internally by Nymph. Don't call it yourself.
36
+ *
37
+ * @returns A clone of this instance.
38
+ */
19
39
  abstract clone(): NymphDriver;
40
+ /**
41
+ * Connect to the data store.
42
+ */
20
43
  abstract connect(): Promise<boolean>;
21
44
  abstract isConnected(): boolean;
45
+ protected abstract internalTransaction(name: string): Promise<any>;
22
46
  abstract startTransaction(name: string): Promise<Nymph>;
23
47
  abstract commit(name: string): Promise<boolean>;
24
48
  abstract rollback(name: string): Promise<boolean>;
@@ -26,61 +50,130 @@ export default abstract class NymphDriver {
26
50
  abstract deleteEntityByID(guid: string, classConstructor: EntityConstructor): Promise<boolean>;
27
51
  abstract deleteEntityByID(guid: string, className?: string): Promise<boolean>;
28
52
  abstract deleteUID(name: string): Promise<boolean>;
53
+ /**
54
+ * Disconnect from the data store.
55
+ */
29
56
  abstract disconnect(): Promise<boolean>;
30
- protected abstract exportEntities(writeLine: (line: string) => void): Promise<void>;
57
+ abstract needsMigration(): Promise<'json' | 'tokens' | 'tilmeldColumns' | false>;
58
+ abstract liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns' | 'tilmeldRemoveOldRows'): Promise<void>;
59
+ abstract getEtypes(): Promise<string[]>;
60
+ abstract getIndexes(etype: string): Promise<{
61
+ scope: 'data' | 'references' | 'tokens';
62
+ name: string;
63
+ property: string;
64
+ }[]>;
65
+ abstract addIndex(etype: string, definition: {
66
+ scope: 'data' | 'references' | 'tokens';
67
+ name: string;
68
+ property: string;
69
+ }): Promise<boolean>;
70
+ abstract deleteIndex(etype: string, scope: 'data' | 'references' | 'tokens', name: string): Promise<boolean>;
71
+ abstract exportDataIterator(): AsyncGenerator<{
72
+ type: 'comment' | 'uid' | 'entity';
73
+ content: string;
74
+ }, void, undefined | false>;
31
75
  abstract getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
32
76
  return: 'count';
33
77
  }, ...selectors: Selector[]): Promise<number>;
34
78
  abstract getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
35
79
  return: 'guid';
36
80
  }, ...selectors: Selector[]): Promise<string[]>;
37
- abstract getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<ReturnType<T['factorySync']>[]>;
38
- abstract getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<ReturnType<T['factorySync']>[] | string[] | number>;
39
- protected abstract getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
40
- return: 'count';
41
- }, ...selectors: Selector[]): number;
42
- protected abstract getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
43
- return: 'guid';
44
- }, ...selectors: Selector[]): string[];
45
- protected abstract getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']>[];
46
- protected abstract getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']>[] | string[] | number;
81
+ abstract getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
82
+ return: 'object';
83
+ }, ...selectors: Selector[]): Promise<EntityObjectType<T>[]>;
84
+ abstract getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[]>;
85
+ abstract getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[] | EntityObjectType<T>[] | string[] | number>;
47
86
  abstract getUID(name: string): Promise<number | null>;
48
- abstract import(filename: string): Promise<boolean>;
87
+ abstract importEntity(entity: {
88
+ guid: string;
89
+ cdate: number;
90
+ mdate: number;
91
+ tags: string[];
92
+ sdata: SerializedEntityData;
93
+ etype: string;
94
+ }): Promise<void>;
95
+ abstract importEntityTokens(entity: {
96
+ guid: string;
97
+ cdate: number;
98
+ mdate: number;
99
+ tags: string[];
100
+ sdata: SerializedEntityData;
101
+ etype: string;
102
+ }): Promise<void>;
103
+ abstract importEntityTilmeldAC(entity: {
104
+ guid: string;
105
+ cdate: number;
106
+ mdate: number;
107
+ tags: string[];
108
+ sdata: SerializedEntityData;
109
+ etype: string;
110
+ }): Promise<void>;
111
+ abstract importUID(uid: {
112
+ name: string;
113
+ value: number;
114
+ }): Promise<void>;
49
115
  abstract newUID(name: string): Promise<number | null>;
50
116
  abstract renameUID(oldName: string, newName: string): Promise<boolean>;
51
117
  abstract saveEntity(entity: EntityInterface): Promise<boolean>;
52
118
  abstract setUID(name: string, value: number): Promise<boolean>;
119
+ /**
120
+ * Initialize the Nymph driver.
121
+ *
122
+ * This is meant to be called internally by Nymph. Don't call this directly.
123
+ *
124
+ * @param nymph The Nymph instance.
125
+ */
53
126
  init(nymph: Nymph): void;
54
127
  protected posixRegexMatch(pattern: string, subject: string, caseInsensitive?: boolean): boolean;
128
+ checkIndexName(name: string): void;
55
129
  export(filename: string): Promise<boolean>;
56
130
  exportPrint(): Promise<boolean>;
57
- protected importFromFile(filename: string, saveEntityCallback: (guid: string, tags: string[], sdata: SerializedEntityData, etype: string) => Promise<void>, saveUIDCallback: (name: string, value: number) => Promise<void>, startTransactionCallback?: (() => Promise<void>) | null, commitTransactionCallback?: (() => Promise<void>) | null): Promise<boolean>;
58
- checkData(data: EntityData, sdata: SerializedEntityData, selectors: Selector[], guid?: string | null, tags?: string[] | null): boolean;
131
+ importDataIterator(lines: Iterable<string>, transaction?: boolean): Promise<boolean>;
132
+ importData(text: string, transaction?: boolean): Promise<boolean>;
133
+ import(filename: string, transaction?: boolean): Promise<boolean>;
134
+ checkData(etype: string, data: EntityData, sdata: SerializedEntityData, selectors: Selector[], guid?: string | null, tags?: string[] | null): boolean;
135
+ /**
136
+ * Remove all copies of an entity from the cache.
137
+ *
138
+ * @param guid The GUID of the entity to remove.
139
+ */
59
140
  protected cleanCache(guid: string): void;
60
141
  deleteEntity(entity: EntityInterface): Promise<boolean>;
142
+ /**
143
+ * Search through a value for an entity reference.
144
+ *
145
+ * @param value Any value to search.
146
+ * @param entity An entity, GUID, or array of either to search for.
147
+ * @returns True if the reference is found, false otherwise.
148
+ */
61
149
  protected entityReferenceSearch(value: any, entity: EntityInterface | EntityReference | string | (EntityInterface | EntityReference | string)[]): boolean;
150
+ protected removeAndReturnACValues(etype: string, data: EntityData, sdata: SerializedEntityData): {
151
+ user: string | null;
152
+ group: string | null;
153
+ acUser: number | null;
154
+ acGroup: number | null;
155
+ acOther: number | null;
156
+ acRead: string[] | null;
157
+ acWrite: string[] | null;
158
+ acFull: string[] | null;
159
+ };
62
160
  formatSelectors(selectors: Selector[], options?: Options): {
63
161
  selectors: FormattedSelector[];
64
162
  qrefs: [Options, ...FormattedSelector[]][];
65
163
  };
66
- protected iterateSelectorsForQuery(selectors: FormattedSelector[], callback: (key: string, value: any, typeIsOr: boolean, typeIsNot: boolean) => string): string[];
67
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
164
+ protected iterateSelectorsForQuery(selectors: FormattedSelector[], callback: (data: {
165
+ key: string;
166
+ value: any;
167
+ typeIsOr: boolean;
168
+ typeIsNot: boolean;
169
+ }) => string): string[];
170
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
68
171
  return: 'count';
69
- }, ...selectors: Selector[]): number;
70
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
71
- return: 'guid';
72
- }, ...selectors: Selector[]): string | null;
73
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']> | null;
74
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
75
- return: 'count';
76
- }, guid: string): number;
77
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
78
- return: 'guid';
79
- }, guid: string): string | null;
80
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T>, guid: string): ReturnType<T['factorySync']> | null;
81
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
82
- return: 'count';
83
- }, selectors: Selector[], performQueryCallback: (options: Options<T>, formattedSelectors: FormattedSelector[], etype: string) => {
172
+ }, selectors: Selector[], performQueryCallback: (data: {
173
+ options: Options<T>;
174
+ selectors: FormattedSelector[];
175
+ etype: string;
176
+ }) => {
84
177
  result: any;
85
178
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
86
179
  tags: string[];
@@ -93,9 +186,13 @@ export default abstract class NymphDriver {
93
186
  result: any;
94
187
  process: () => number | Error;
95
188
  };
96
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
189
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
97
190
  return: 'guid';
98
- }, selectors: Selector[], performQueryCallback: (options: Options<T>, formattedSelectors: FormattedSelector[], etype: string) => {
191
+ }, selectors: Selector[], performQueryCallback: (data: {
192
+ options: Options<T>;
193
+ selectors: FormattedSelector[];
194
+ etype: string;
195
+ }) => {
99
196
  result: any;
100
197
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
101
198
  tags: string[];
@@ -108,7 +205,13 @@ export default abstract class NymphDriver {
108
205
  result: any;
109
206
  process: () => string[] | Error;
110
207
  };
111
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T>, selectors: Selector[], performQueryCallback: (options: Options<T>, formattedSelectors: FormattedSelector[], etype: string) => {
208
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
209
+ return: 'object';
210
+ }, selectors: Selector[], performQueryCallback: (data: {
211
+ options: Options<T>;
212
+ selectors: FormattedSelector[];
213
+ etype: string;
214
+ }) => {
112
215
  result: any;
113
216
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
114
217
  tags: string[];
@@ -119,10 +222,68 @@ export default abstract class NymphDriver {
119
222
  svalue: string;
120
223
  }): {
121
224
  result: any;
122
- process: () => ReturnType<T['factorySync']>[] | Error;
225
+ process: () => EntityObjectType<T>[] | Error;
123
226
  };
124
- protected saveEntityRowLike(entity: EntityInterface, saveNewEntityCallback: (entity: EntityInterface, guid: string, tags: string[], data: EntityData, sdata: SerializedEntityData, cdate: number, etype: string) => Promise<boolean>, saveExistingEntityCallback: (entity: EntityInterface, guid: string, tags: string[], data: EntityData, sdata: SerializedEntityData, mdate: number, etype: string) => Promise<boolean>, startTransactionCallback?: (() => Promise<void>) | null, commitTransactionCallback?: ((success: boolean) => Promise<boolean>) | null): Promise<boolean>;
125
- protected pullCache<T extends EntityInterface = EntityInterface>(guid: string, className: string, useSkipAc?: boolean): T | null;
227
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T>, selectors: Selector[], performQueryCallback: (data: {
228
+ options: Options<T>;
229
+ selectors: FormattedSelector[];
230
+ etype: string;
231
+ }) => {
232
+ result: any;
233
+ }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
234
+ tags: string[];
235
+ cdate: number;
236
+ mdate: number;
237
+ }, getDataNameAndSValueCallback: (row: any) => {
238
+ name: string;
239
+ svalue: string;
240
+ }): {
241
+ result: any;
242
+ process: () => EntityInstanceType<T>[] | Error;
243
+ };
244
+ protected saveEntityRowLike(entity: EntityInterface, saveNewEntityCallback: (data: {
245
+ entity: EntityInterface;
246
+ guid: string;
247
+ tags: string[];
248
+ data: EntityData;
249
+ sdata: SerializedEntityData;
250
+ uniques: string[];
251
+ cdate: number;
252
+ etype: string;
253
+ }) => Promise<boolean>, saveExistingEntityCallback: (data: {
254
+ entity: EntityInterface;
255
+ guid: string;
256
+ tags: string[];
257
+ data: EntityData;
258
+ sdata: SerializedEntityData;
259
+ uniques: string[];
260
+ mdate: number;
261
+ etype: string;
262
+ }) => Promise<boolean>, startTransactionCallback?: (() => Promise<void>) | null, commitTransactionCallback?: ((success: boolean) => Promise<boolean>) | null): Promise<boolean>;
263
+ /**
264
+ * Pull an entity from the cache.
265
+ *
266
+ * @param guid The entity's GUID.
267
+ * @returns The entity's data or null if it's not cached.
268
+ */
269
+ protected pullCache(guid: string): {
270
+ guid: string;
271
+ cdate: number;
272
+ mdate: number;
273
+ tags: string[];
274
+ data: EntityData;
275
+ sdata: SerializedEntityData;
276
+ } | null;
277
+ /**
278
+ * Push an entity onto the cache.
279
+ *
280
+ * @param guid The entity's GUID.
281
+ * @param cdate The entity's cdate.
282
+ * @param mdate The entity's mdate.
283
+ * @param tags The entity's tags.
284
+ * @param data The entity's data.
285
+ * @param sdata The entity's sdata.
286
+ */
126
287
  protected pushCache(guid: string, cdate: number, mdate: number, tags: string[], data: EntityData, sdata: SerializedEntityData): void;
127
288
  protected findReferences(svalue: string): string[];
128
289
  }