@nymphjs/nymph 1.0.0-beta.1 → 1.0.0-beta.100

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 (96) hide show
  1. package/CHANGELOG.md +535 -0
  2. package/README.md +14 -22
  3. package/dist/Entity.d.ts +293 -10
  4. package/dist/Entity.js +571 -149
  5. package/dist/Entity.js.map +1 -1
  6. package/dist/Entity.test.js +67 -26
  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 +497 -13
  11. package/dist/Nymph.js +761 -188
  12. package/dist/Nymph.js.map +1 -1
  13. package/dist/Nymph.types.d.ts +95 -26
  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 +181 -43
  25. package/dist/driver/NymphDriver.js +532 -285
  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 +939 -219
  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/InvalidParametersError.js +1 -5
  46. package/dist/errors/InvalidParametersError.js.map +1 -1
  47. package/dist/errors/InvalidStateError.d.ts +3 -0
  48. package/dist/errors/InvalidStateError.js +7 -0
  49. package/dist/errors/InvalidStateError.js.map +1 -0
  50. package/dist/errors/NotConfiguredError.js +1 -5
  51. package/dist/errors/NotConfiguredError.js.map +1 -1
  52. package/dist/errors/QueryFailedError.js +2 -5
  53. package/dist/errors/QueryFailedError.js.map +1 -1
  54. package/dist/errors/UnableToConnectError.js +1 -5
  55. package/dist/errors/UnableToConnectError.js.map +1 -1
  56. package/dist/errors/index.d.ts +10 -8
  57. package/dist/errors/index.js +10 -24
  58. package/dist/errors/index.js.map +1 -1
  59. package/dist/index.d.ts +11 -11
  60. package/dist/index.js +14 -34
  61. package/dist/index.js.map +1 -1
  62. package/dist/nymphJoiProps.js +10 -15
  63. package/dist/nymphJoiProps.js.map +1 -1
  64. package/dist/testArtifacts.d.ts +19 -6
  65. package/dist/testArtifacts.js +32 -37
  66. package/dist/testArtifacts.js.map +1 -1
  67. package/dist/testMocks.d.ts +28 -11
  68. package/dist/testMocks.js +44 -28
  69. package/dist/testMocks.js.map +1 -1
  70. package/dist/utils.d.ts +4 -4
  71. package/dist/utils.js +40 -29
  72. package/dist/utils.js.map +1 -1
  73. package/jest.config.js +11 -2
  74. package/package.json +24 -20
  75. package/src/Entity.test.ts +63 -13
  76. package/src/Entity.ts +498 -156
  77. package/src/Entity.types.ts +72 -74
  78. package/src/Nymph.ts +904 -336
  79. package/src/Nymph.types.ts +179 -44
  80. package/src/conf/d.ts +25 -0
  81. package/src/conf/defaults.ts +34 -1
  82. package/src/conf/index.ts +2 -2
  83. package/src/driver/NymphDriver.ts +650 -460
  84. package/src/driver/index.ts +2 -2
  85. package/src/driver/testArtifacts.ts +966 -196
  86. package/src/errors/EntityUniqueConstraintError.ts +6 -0
  87. package/src/errors/InvalidStateError.ts +6 -0
  88. package/src/errors/index.ts +12 -8
  89. package/src/index.ts +11 -11
  90. package/src/nymphJoiProps.ts +2 -2
  91. package/src/testArtifacts.ts +20 -20
  92. package/src/testMocks.ts +85 -37
  93. package/src/type/locutus.d.ts +3 -0
  94. package/src/utils.ts +39 -18
  95. package/tsconfig.json +5 -3
  96. 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,12 +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
+ */
39
+ abstract clone(): NymphDriver;
40
+ /**
41
+ * Connect to the data store.
42
+ */
19
43
  abstract connect(): Promise<boolean>;
20
44
  abstract isConnected(): boolean;
45
+ protected abstract internalTransaction(name: string): Promise<any>;
21
46
  abstract startTransaction(name: string): Promise<Nymph>;
22
47
  abstract commit(name: string): Promise<boolean>;
23
48
  abstract rollback(name: string): Promise<boolean>;
@@ -25,58 +50,103 @@ export default abstract class NymphDriver {
25
50
  abstract deleteEntityByID(guid: string, classConstructor: EntityConstructor): Promise<boolean>;
26
51
  abstract deleteEntityByID(guid: string, className?: string): Promise<boolean>;
27
52
  abstract deleteUID(name: string): Promise<boolean>;
53
+ /**
54
+ * Disconnect from the data store.
55
+ */
28
56
  abstract disconnect(): Promise<boolean>;
29
- protected abstract exportEntities(writeLine: (line: string) => void): Promise<void>;
57
+ abstract needsMigration(): Promise<'json' | 'tokens' | false>;
58
+ abstract liveMigration(migrationType: 'tokenTables'): Promise<void>;
59
+ /**
60
+ * Returns a list of the etypes stored in the DB.
61
+ */
62
+ abstract getEtypes(): Promise<string[]>;
63
+ abstract exportDataIterator(): AsyncGenerator<{
64
+ type: 'comment' | 'uid' | 'entity';
65
+ content: string;
66
+ }, void, undefined | false>;
30
67
  abstract getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
31
68
  return: 'count';
32
69
  }, ...selectors: Selector[]): Promise<number>;
33
70
  abstract getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
34
71
  return: 'guid';
35
72
  }, ...selectors: Selector[]): Promise<string[]>;
36
- abstract getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<ReturnType<T['factorySync']>[]>;
37
- abstract getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<ReturnType<T['factorySync']>[] | string[] | number>;
38
- protected abstract getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
39
- return: 'count';
40
- }, ...selectors: Selector[]): number;
41
- protected abstract getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
42
- return: 'guid';
43
- }, ...selectors: Selector[]): string[];
44
- protected abstract getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']>[];
45
- protected abstract getEntitiesSync<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']>[] | string[] | number;
73
+ abstract getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
74
+ return: 'object';
75
+ }, ...selectors: Selector[]): Promise<EntityObjectType<T>[]>;
76
+ abstract getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[]>;
77
+ abstract getEntities<T extends EntityConstructor = EntityConstructor>(options?: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[] | EntityObjectType<T>[] | string[] | number>;
46
78
  abstract getUID(name: string): Promise<number | null>;
47
- abstract import(filename: string): Promise<boolean>;
79
+ abstract importEntity(entity: {
80
+ guid: string;
81
+ cdate: number;
82
+ mdate: number;
83
+ tags: string[];
84
+ sdata: SerializedEntityData;
85
+ etype: string;
86
+ }): Promise<void>;
87
+ abstract importEntityTokens(entity: {
88
+ guid: string;
89
+ cdate: number;
90
+ mdate: number;
91
+ tags: string[];
92
+ sdata: SerializedEntityData;
93
+ etype: string;
94
+ }): Promise<void>;
95
+ abstract importUID(uid: {
96
+ name: string;
97
+ value: number;
98
+ }): Promise<void>;
48
99
  abstract newUID(name: string): Promise<number | null>;
49
100
  abstract renameUID(oldName: string, newName: string): Promise<boolean>;
50
101
  abstract saveEntity(entity: EntityInterface): Promise<boolean>;
51
102
  abstract setUID(name: string, value: number): Promise<boolean>;
103
+ /**
104
+ * Initialize the Nymph driver.
105
+ *
106
+ * This is meant to be called internally by Nymph. Don't call this directly.
107
+ *
108
+ * @param nymph The Nymph instance.
109
+ */
52
110
  init(nymph: Nymph): void;
53
111
  protected posixRegexMatch(pattern: string, subject: string, caseInsensitive?: boolean): boolean;
54
112
  export(filename: string): Promise<boolean>;
55
113
  exportPrint(): Promise<boolean>;
56
- 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>;
57
- checkData(data: EntityData, sdata: SerializedEntityData, selectors: Selector[], guid?: string | null, tags?: string[] | null): boolean;
114
+ importDataIterator(lines: Iterable<string>, transaction?: boolean): Promise<boolean>;
115
+ importData(text: string, transaction?: boolean): Promise<boolean>;
116
+ import(filename: string, transaction?: boolean): Promise<boolean>;
117
+ checkData(etype: string, data: EntityData, sdata: SerializedEntityData, selectors: Selector[], guid?: string | null, tags?: string[] | null): boolean;
118
+ /**
119
+ * Remove all copies of an entity from the cache.
120
+ *
121
+ * @param guid The GUID of the entity to remove.
122
+ */
58
123
  protected cleanCache(guid: string): void;
59
124
  deleteEntity(entity: EntityInterface): Promise<boolean>;
125
+ /**
126
+ * Search through a value for an entity reference.
127
+ *
128
+ * @param value Any value to search.
129
+ * @param entity An entity, GUID, or array of either to search for.
130
+ * @returns True if the reference is found, false otherwise.
131
+ */
60
132
  protected entityReferenceSearch(value: any, entity: EntityInterface | EntityReference | string | (EntityInterface | EntityReference | string)[]): boolean;
61
- formatSelectors(selectors: Selector[], options?: Options): FormattedSelector[];
62
- protected iterateSelectorsForQuery(selectors: FormattedSelector[], callback: (key: string, value: any, typeIsOr: boolean, typeIsNot: boolean) => string): string[];
63
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
64
- return: 'count';
65
- }, ...selectors: Selector[]): number;
66
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
67
- return: 'guid';
68
- }, ...selectors: Selector[]): string | null;
69
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): ReturnType<T['factorySync']> | null;
70
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
71
- return: 'count';
72
- }, guid: string): number;
73
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
74
- return: 'guid';
75
- }, guid: string): string | null;
76
- getEntitySync<T extends EntityConstructor = EntityConstructor>(options: Options<T>, guid: string): ReturnType<T['factorySync']> | null;
77
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
133
+ formatSelectors(selectors: Selector[], options?: Options): {
134
+ selectors: FormattedSelector[];
135
+ qrefs: [Options, ...FormattedSelector[]][];
136
+ };
137
+ protected iterateSelectorsForQuery(selectors: FormattedSelector[], callback: (data: {
138
+ key: string;
139
+ value: any;
140
+ typeIsOr: boolean;
141
+ typeIsNot: boolean;
142
+ }) => string): string[];
143
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
78
144
  return: 'count';
79
- }, selectors: Selector[], performQueryCallback: (options: Options<T>, formattedSelectors: FormattedSelector[], etype: string) => {
145
+ }, selectors: Selector[], performQueryCallback: (data: {
146
+ options: Options<T>;
147
+ selectors: FormattedSelector[];
148
+ etype: string;
149
+ }) => {
80
150
  result: any;
81
151
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
82
152
  tags: string[];
@@ -87,11 +157,15 @@ export default abstract class NymphDriver {
87
157
  svalue: string;
88
158
  }): {
89
159
  result: any;
90
- process: () => number;
160
+ process: () => number | Error;
91
161
  };
92
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
162
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
93
163
  return: 'guid';
94
- }, selectors: Selector[], performQueryCallback: (options: Options<T>, formattedSelectors: FormattedSelector[], etype: string) => {
164
+ }, selectors: Selector[], performQueryCallback: (data: {
165
+ options: Options<T>;
166
+ selectors: FormattedSelector[];
167
+ etype: string;
168
+ }) => {
95
169
  result: any;
96
170
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
97
171
  tags: string[];
@@ -102,9 +176,15 @@ export default abstract class NymphDriver {
102
176
  svalue: string;
103
177
  }): {
104
178
  result: any;
105
- process: () => string[];
179
+ process: () => string[] | Error;
106
180
  };
107
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T>, selectors: Selector[], performQueryCallback: (options: Options<T>, formattedSelectors: FormattedSelector[], etype: string) => {
181
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
182
+ return: 'object';
183
+ }, selectors: Selector[], performQueryCallback: (data: {
184
+ options: Options<T>;
185
+ selectors: FormattedSelector[];
186
+ etype: string;
187
+ }) => {
108
188
  result: any;
109
189
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
110
190
  tags: string[];
@@ -115,10 +195,68 @@ export default abstract class NymphDriver {
115
195
  svalue: string;
116
196
  }): {
117
197
  result: any;
118
- process: () => ReturnType<T['factorySync']>[];
198
+ process: () => EntityObjectType<T>[] | Error;
119
199
  };
120
- 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>;
121
- protected pullCache<T extends EntityInterface = EntityInterface>(guid: string, className: string, useSkipAc?: boolean): T | null;
200
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T>, selectors: Selector[], performQueryCallback: (data: {
201
+ options: Options<T>;
202
+ selectors: FormattedSelector[];
203
+ etype: string;
204
+ }) => {
205
+ result: any;
206
+ }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
207
+ tags: string[];
208
+ cdate: number;
209
+ mdate: number;
210
+ }, getDataNameAndSValueCallback: (row: any) => {
211
+ name: string;
212
+ svalue: string;
213
+ }): {
214
+ result: any;
215
+ process: () => EntityInstanceType<T>[] | Error;
216
+ };
217
+ protected saveEntityRowLike(entity: EntityInterface, saveNewEntityCallback: (data: {
218
+ entity: EntityInterface;
219
+ guid: string;
220
+ tags: string[];
221
+ data: EntityData;
222
+ sdata: SerializedEntityData;
223
+ uniques: string[];
224
+ cdate: number;
225
+ etype: string;
226
+ }) => Promise<boolean>, saveExistingEntityCallback: (data: {
227
+ entity: EntityInterface;
228
+ guid: string;
229
+ tags: string[];
230
+ data: EntityData;
231
+ sdata: SerializedEntityData;
232
+ uniques: string[];
233
+ mdate: number;
234
+ etype: string;
235
+ }) => Promise<boolean>, startTransactionCallback?: (() => Promise<void>) | null, commitTransactionCallback?: ((success: boolean) => Promise<boolean>) | null): Promise<boolean>;
236
+ /**
237
+ * Pull an entity from the cache.
238
+ *
239
+ * @param guid The entity's GUID.
240
+ * @returns The entity's data or null if it's not cached.
241
+ */
242
+ protected pullCache(guid: string): {
243
+ guid: string;
244
+ cdate: number;
245
+ mdate: number;
246
+ tags: string[];
247
+ data: EntityData;
248
+ sdata: SerializedEntityData;
249
+ } | null;
250
+ /**
251
+ * Push an entity onto the cache.
252
+ *
253
+ * @param guid The entity's GUID.
254
+ * @param cdate The entity's cdate.
255
+ * @param mdate The entity's mdate.
256
+ * @param tags The entity's tags.
257
+ * @param data The entity's data.
258
+ * @param sdata The entity's sdata.
259
+ */
122
260
  protected pushCache(guid: string, cdate: number, mdate: number, tags: string[], data: EntityData, sdata: SerializedEntityData): void;
123
261
  protected findReferences(svalue: string): string[];
124
262
  }