@nymphjs/nymph 1.0.0-beta.10 → 1.0.0-beta.101

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 (97) hide show
  1. package/CHANGELOG.md +487 -0
  2. package/README.md +10 -20
  3. package/dist/Entity.d.ts +293 -10
  4. package/dist/Entity.js +563 -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 +496 -12
  11. package/dist/Nymph.js +752 -179
  12. package/dist/Nymph.js.map +1 -1
  13. package/dist/Nymph.types.d.ts +77 -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 +174 -40
  25. package/dist/driver/NymphDriver.js +469 -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 +814 -92
  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.d.ts +1 -1
  63. package/dist/nymphJoiProps.js +10 -15
  64. package/dist/nymphJoiProps.js.map +1 -1
  65. package/dist/testArtifacts.d.ts +19 -6
  66. package/dist/testArtifacts.js +32 -37
  67. package/dist/testArtifacts.js.map +1 -1
  68. package/dist/testMocks.d.ts +27 -12
  69. package/dist/testMocks.js +40 -29
  70. package/dist/testMocks.js.map +1 -1
  71. package/dist/utils.d.ts +4 -4
  72. package/dist/utils.js +40 -29
  73. package/dist/utils.js.map +1 -1
  74. package/jest.config.js +11 -2
  75. package/package.json +23 -19
  76. package/src/Entity.test.ts +50 -7
  77. package/src/Entity.ts +483 -147
  78. package/src/Entity.types.ts +72 -74
  79. package/src/Nymph.ts +868 -322
  80. package/src/Nymph.types.ts +146 -27
  81. package/src/conf/d.ts +25 -0
  82. package/src/conf/defaults.ts +34 -1
  83. package/src/conf/index.ts +2 -2
  84. package/src/driver/NymphDriver.ts +562 -414
  85. package/src/driver/index.ts +2 -2
  86. package/src/driver/testArtifacts.ts +954 -185
  87. package/src/errors/EntityUniqueConstraintError.ts +6 -0
  88. package/src/errors/InvalidStateError.ts +6 -0
  89. package/src/errors/index.ts +12 -8
  90. package/src/index.ts +11 -11
  91. package/src/nymphJoiProps.ts +2 -2
  92. package/src/testArtifacts.ts +20 -20
  93. package/src/testMocks.ts +76 -35
  94. package/src/type/locutus.d.ts +3 -0
  95. package/src/utils.ts +39 -18
  96. package/tsconfig.json +5 -3
  97. 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,103 @@ 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' | 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>;
31
67
  abstract getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
32
68
  return: 'count';
33
69
  }, ...selectors: Selector[]): Promise<number>;
34
70
  abstract getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
35
71
  return: 'guid';
36
72
  }, ...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;
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>;
47
78
  abstract getUID(name: string): Promise<number | null>;
48
- 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>;
49
99
  abstract newUID(name: string): Promise<number | null>;
50
100
  abstract renameUID(oldName: string, newName: string): Promise<boolean>;
51
101
  abstract saveEntity(entity: EntityInterface): Promise<boolean>;
52
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
+ */
53
110
  init(nymph: Nymph): void;
54
111
  protected posixRegexMatch(pattern: string, subject: string, caseInsensitive?: boolean): boolean;
55
112
  export(filename: string): Promise<boolean>;
56
113
  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;
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
+ */
59
123
  protected cleanCache(guid: string): void;
60
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
+ */
61
132
  protected entityReferenceSearch(value: any, entity: EntityInterface | EntityReference | string | (EntityInterface | EntityReference | string)[]): boolean;
62
133
  formatSelectors(selectors: Selector[], options?: Options): {
63
134
  selectors: FormattedSelector[];
64
135
  qrefs: [Options, ...FormattedSelector[]][];
65
136
  };
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> & {
68
- 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> & {
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> & {
82
144
  return: 'count';
83
- }, 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
+ }) => {
84
150
  result: any;
85
151
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
86
152
  tags: string[];
@@ -93,9 +159,13 @@ export default abstract class NymphDriver {
93
159
  result: any;
94
160
  process: () => number | Error;
95
161
  };
96
- protected getEntitesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
162
+ protected getEntitiesRowLike<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
97
163
  return: 'guid';
98
- }, 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
+ }) => {
99
169
  result: any;
100
170
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
101
171
  tags: string[];
@@ -108,7 +178,30 @@ export default abstract class NymphDriver {
108
178
  result: any;
109
179
  process: () => string[] | Error;
110
180
  };
111
- 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
+ }) => {
188
+ result: any;
189
+ }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
190
+ tags: string[];
191
+ cdate: number;
192
+ mdate: number;
193
+ }, getDataNameAndSValueCallback: (row: any) => {
194
+ name: string;
195
+ svalue: string;
196
+ }): {
197
+ result: any;
198
+ process: () => EntityObjectType<T>[] | Error;
199
+ };
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
+ }) => {
112
205
  result: any;
113
206
  }, rowFetchCallback: () => any, freeResultCallback: () => void, getCountCallback: (row: any) => number, getGUIDCallback: (row: any) => string, getTagsAndDatesCallback: (row: any) => {
114
207
  tags: string[];
@@ -119,10 +212,51 @@ export default abstract class NymphDriver {
119
212
  svalue: string;
120
213
  }): {
121
214
  result: any;
122
- process: () => ReturnType<T['factorySync']>[] | Error;
215
+ process: () => EntityInstanceType<T>[] | Error;
123
216
  };
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;
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
+ */
126
260
  protected pushCache(guid: string, cdate: number, mdate: number, tags: string[], data: EntityData, sdata: SerializedEntityData): void;
127
261
  protected findReferences(svalue: string): string[];
128
262
  }