@nymphjs/nymph 1.0.0-beta.12 → 1.0.0-beta.121

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 +588 -0
  2. package/README.md +23 -21
  3. package/dist/Entity.d.ts +295 -12
  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 +590 -13
  11. package/dist/Nymph.js +846 -180
  12. package/dist/Nymph.js.map +1 -1
  13. package/dist/Nymph.types.d.ts +131 -8
  14. package/dist/Nymph.types.js +47 -5
  15. package/dist/Nymph.types.js.map +1 -1
  16. package/dist/conf/defaults.d.ts +1 -1
  17. package/dist/conf/defaults.js +26 -3
  18. package/dist/conf/defaults.js.map +1 -1
  19. package/dist/conf/index.d.ts +50 -2
  20. package/dist/conf/index.js +2 -8
  21. package/dist/conf/index.js.map +1 -1
  22. package/dist/driver/NymphDriver.d.ts +205 -40
  23. package/dist/driver/NymphDriver.js +712 -238
  24. package/dist/driver/NymphDriver.js.map +1 -1
  25. package/dist/driver/index.d.ts +1 -2
  26. package/dist/driver/index.js +2 -23
  27. package/dist/driver/index.js.map +1 -1
  28. package/dist/driver/testArtifacts.d.ts +4 -4
  29. package/dist/driver/testArtifacts.js +1920 -1086
  30. package/dist/driver/testArtifacts.js.map +1 -1
  31. package/dist/errors/ClassNotAvailableError.js +1 -5
  32. package/dist/errors/ClassNotAvailableError.js.map +1 -1
  33. package/dist/errors/EntityConflictError.js +1 -5
  34. package/dist/errors/EntityConflictError.js.map +1 -1
  35. package/dist/errors/EntityInvalidDataError.d.ts +6 -0
  36. package/dist/errors/EntityInvalidDataError.js +8 -6
  37. package/dist/errors/EntityInvalidDataError.js.map +1 -1
  38. package/dist/errors/EntityIsSleepingReferenceError.js +1 -5
  39. package/dist/errors/EntityIsSleepingReferenceError.js.map +1 -1
  40. package/dist/errors/EntityUniqueConstraintError.d.ts +3 -0
  41. package/dist/errors/EntityUniqueConstraintError.js +7 -0
  42. package/dist/errors/EntityUniqueConstraintError.js.map +1 -0
  43. package/dist/errors/HttpError.d.ts +5 -0
  44. package/dist/errors/HttpError.js +11 -0
  45. package/dist/errors/HttpError.js.map +1 -0
  46. package/dist/errors/InvalidParametersError.js +1 -5
  47. package/dist/errors/InvalidParametersError.js.map +1 -1
  48. package/dist/errors/InvalidStateError.d.ts +3 -0
  49. package/dist/errors/InvalidStateError.js +7 -0
  50. package/dist/errors/InvalidStateError.js.map +1 -0
  51. package/dist/errors/NotConfiguredError.js +1 -5
  52. package/dist/errors/NotConfiguredError.js.map +1 -1
  53. package/dist/errors/QueryFailedError.d.ts +2 -1
  54. package/dist/errors/QueryFailedError.js +5 -6
  55. package/dist/errors/QueryFailedError.js.map +1 -1
  56. package/dist/errors/UnableToConnectError.js +1 -5
  57. package/dist/errors/UnableToConnectError.js.map +1 -1
  58. package/dist/errors/index.d.ts +11 -8
  59. package/dist/errors/index.js +11 -24
  60. package/dist/errors/index.js.map +1 -1
  61. package/dist/index.d.ts +11 -11
  62. package/dist/index.js +14 -34
  63. package/dist/index.js.map +1 -1
  64. package/dist/nymphJoiProps.d.ts +1 -1
  65. package/dist/nymphJoiProps.js +10 -15
  66. package/dist/nymphJoiProps.js.map +1 -1
  67. package/dist/testArtifacts.d.ts +19 -6
  68. package/dist/testArtifacts.js +32 -37
  69. package/dist/testArtifacts.js.map +1 -1
  70. package/dist/testMocks.d.ts +27 -12
  71. package/dist/testMocks.js +40 -29
  72. package/dist/testMocks.js.map +1 -1
  73. package/dist/utils.d.ts +4 -4
  74. package/dist/utils.js +40 -29
  75. package/dist/utils.js.map +1 -1
  76. package/jest.config.js +31 -5
  77. package/package.json +33 -23
  78. package/src/Entity.test.ts +50 -7
  79. package/src/Entity.ts +489 -150
  80. package/src/Entity.types.ts +72 -74
  81. package/src/Nymph.ts +991 -324
  82. package/src/Nymph.types.ts +201 -27
  83. package/src/conf/defaults.ts +34 -1
  84. package/src/conf/index.ts +50 -2
  85. package/src/driver/NymphDriver.ts +898 -413
  86. package/src/driver/index.ts +1 -3
  87. package/src/driver/testArtifacts.ts +2557 -1629
  88. package/src/errors/EntityUniqueConstraintError.ts +6 -0
  89. package/src/errors/HttpError.ts +12 -0
  90. package/src/errors/InvalidStateError.ts +6 -0
  91. package/src/errors/QueryFailedError.ts +3 -1
  92. package/src/errors/index.ts +14 -8
  93. package/src/index.ts +11 -11
  94. package/src/nymphJoiProps.ts +2 -2
  95. package/src/testArtifacts.ts +20 -20
  96. package/src/testMocks.ts +76 -35
  97. package/src/utils.ts +39 -18
  98. package/tsconfig.json +6 -3
  99. package/typedoc.json +4 -0
  100. package/dist/conf/d.d.ts +0 -6
  101. package/dist/conf/d.js +0 -3
  102. package/dist/conf/d.js.map +0 -1
  103. package/src/conf/d.ts +0 -24
@@ -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,134 @@ 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>, options?: {
132
+ ignoreUnknownETypes?: boolean;
133
+ }, transaction?: boolean): Promise<boolean>;
134
+ importData(text: string, transaction?: boolean): Promise<boolean>;
135
+ import(filename: string, options?: {
136
+ ignoreUnknownETypes?: boolean;
137
+ }, transaction?: boolean): Promise<boolean>;
138
+ checkData(etype: string, data: EntityData, sdata: SerializedEntityData, selectors: Selector[], guid?: string | null, tags?: string[] | null): boolean;
139
+ /**
140
+ * Remove all copies of an entity from the cache.
141
+ *
142
+ * @param guid The GUID of the entity to remove.
143
+ */
59
144
  protected cleanCache(guid: string): void;
60
145
  deleteEntity(entity: EntityInterface): Promise<boolean>;
146
+ /**
147
+ * Search through a value for an entity reference.
148
+ *
149
+ * @param value Any value to search.
150
+ * @param entity An entity, GUID, or array of either to search for.
151
+ * @returns True if the reference is found, false otherwise.
152
+ */
61
153
  protected entityReferenceSearch(value: any, entity: EntityInterface | EntityReference | string | (EntityInterface | EntityReference | string)[]): boolean;
154
+ protected removeAndReturnACValues(etype: string, data: EntityData, sdata: SerializedEntityData): {
155
+ user: string | null;
156
+ group: string | null;
157
+ acUser: number | null;
158
+ acGroup: number | null;
159
+ acOther: number | null;
160
+ acRead: string[] | null;
161
+ acWrite: string[] | null;
162
+ acFull: string[] | null;
163
+ };
62
164
  formatSelectors(selectors: Selector[], options?: Options): {
63
165
  selectors: FormattedSelector[];
64
166
  qrefs: [Options, ...FormattedSelector[]][];
65
167
  };
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> & {
168
+ protected iterateSelectorsForQuery(selectors: FormattedSelector[], callback: (data: {
169
+ key: string;
170
+ value: any;
171
+ typeIsOr: boolean;
172
+ typeIsNot: boolean;
173
+ }) => string): string[];
174
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
68
175
  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) => {
176
+ }, selectors: Selector[], performQueryCallback: (data: {
177
+ options: Options<T>;
178
+ selectors: FormattedSelector[];
179
+ etype: string;
180
+ }) => {
84
181
  result: any;
85
182
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
86
183
  tags: string[];
@@ -93,9 +190,13 @@ export default abstract class NymphDriver {
93
190
  result: any;
94
191
  process: () => number | Error;
95
192
  };
96
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
193
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
97
194
  return: 'guid';
98
- }, selectors: Selector[], performQueryCallback: (options: Options<T>, formattedSelectors: FormattedSelector[], etype: string) => {
195
+ }, selectors: Selector[], performQueryCallback: (data: {
196
+ options: Options<T>;
197
+ selectors: FormattedSelector[];
198
+ etype: string;
199
+ }) => {
99
200
  result: any;
100
201
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
101
202
  tags: string[];
@@ -108,7 +209,13 @@ export default abstract class NymphDriver {
108
209
  result: any;
109
210
  process: () => string[] | Error;
110
211
  };
111
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T>, selectors: Selector[], performQueryCallback: (options: Options<T>, formattedSelectors: FormattedSelector[], etype: string) => {
212
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
213
+ return: 'object';
214
+ }, selectors: Selector[], performQueryCallback: (data: {
215
+ options: Options<T>;
216
+ selectors: FormattedSelector[];
217
+ etype: string;
218
+ }) => {
112
219
  result: any;
113
220
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
114
221
  tags: string[];
@@ -119,10 +226,68 @@ export default abstract class NymphDriver {
119
226
  svalue: string;
120
227
  }): {
121
228
  result: any;
122
- process: () => ReturnType<T['factorySync']>[] | Error;
229
+ process: () => EntityObjectType<T>[] | Error;
123
230
  };
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;
231
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T>, selectors: Selector[], performQueryCallback: (data: {
232
+ options: Options<T>;
233
+ selectors: FormattedSelector[];
234
+ etype: string;
235
+ }) => {
236
+ result: any;
237
+ }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
238
+ tags: string[];
239
+ cdate: number;
240
+ mdate: number;
241
+ }, getDataNameAndSValueCallback: (row: any) => {
242
+ name: string;
243
+ svalue: string;
244
+ }): {
245
+ result: any;
246
+ process: () => EntityInstanceType<T>[] | Error;
247
+ };
248
+ protected saveEntityRowLike(entity: EntityInterface, saveNewEntityCallback: (data: {
249
+ entity: EntityInterface;
250
+ guid: string;
251
+ tags: string[];
252
+ data: EntityData;
253
+ sdata: SerializedEntityData;
254
+ uniques: string[];
255
+ cdate: number;
256
+ etype: string;
257
+ }) => Promise<boolean>, saveExistingEntityCallback: (data: {
258
+ entity: EntityInterface;
259
+ guid: string;
260
+ tags: string[];
261
+ data: EntityData;
262
+ sdata: SerializedEntityData;
263
+ uniques: string[];
264
+ mdate: number;
265
+ etype: string;
266
+ }) => Promise<boolean>, startTransactionCallback?: (() => Promise<void>) | null, commitTransactionCallback?: ((success: boolean) => Promise<boolean>) | null): Promise<boolean>;
267
+ /**
268
+ * Pull an entity from the cache.
269
+ *
270
+ * @param guid The entity's GUID.
271
+ * @returns The entity's data or null if it's not cached.
272
+ */
273
+ protected pullCache(guid: string): {
274
+ guid: string;
275
+ cdate: number;
276
+ mdate: number;
277
+ tags: string[];
278
+ data: EntityData;
279
+ sdata: SerializedEntityData;
280
+ } | null;
281
+ /**
282
+ * Push an entity onto the cache.
283
+ *
284
+ * @param guid The entity's GUID.
285
+ * @param cdate The entity's cdate.
286
+ * @param mdate The entity's mdate.
287
+ * @param tags The entity's tags.
288
+ * @param data The entity's data.
289
+ * @param sdata The entity's sdata.
290
+ */
126
291
  protected pushCache(guid: string, cdate: number, mdate: number, tags: string[], data: EntityData, sdata: SerializedEntityData): void;
127
292
  protected findReferences(svalue: string): string[];
128
293
  }