@nymphjs/client 1.0.0-beta.13 → 1.0.0-beta.130

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 (72) hide show
  1. package/CHANGELOG.md +546 -0
  2. package/README.md +12 -8
  3. package/asyncitertest.js +53 -0
  4. package/dist/Entity.d.ts +156 -0
  5. package/{lib → dist}/Entity.js +244 -118
  6. package/dist/Entity.js.map +1 -0
  7. package/dist/Entity.types.d.ts +216 -0
  8. package/dist/Entity.types.js +2 -0
  9. package/{lib → dist}/EntityWeakCache.d.ts +1 -1
  10. package/{lib → dist}/EntityWeakCache.js +5 -9
  11. package/dist/EntityWeakCache.js.map +1 -0
  12. package/{lib → dist}/HttpRequester.d.ts +18 -4
  13. package/dist/HttpRequester.js +365 -0
  14. package/dist/HttpRequester.js.map +1 -0
  15. package/{lib → dist}/Nymph.d.ts +48 -11
  16. package/{lib → dist}/Nymph.js +172 -56
  17. package/dist/Nymph.js.map +1 -0
  18. package/dist/Nymph.types.d.ts +227 -0
  19. package/dist/Nymph.types.js +45 -0
  20. package/dist/Nymph.types.js.map +1 -0
  21. package/{lib → dist}/PubSub.d.ts +16 -10
  22. package/{lib → dist}/PubSub.js +207 -135
  23. package/dist/PubSub.js.map +1 -0
  24. package/{lib → dist}/PubSub.types.d.ts +19 -6
  25. package/dist/PubSub.types.js +2 -0
  26. package/{lib → dist}/entityRefresh.d.ts +1 -1
  27. package/{lib → dist}/entityRefresh.js +21 -13
  28. package/dist/entityRefresh.js.map +1 -0
  29. package/dist/index.d.ts +13 -0
  30. package/dist/index.js +13 -2
  31. package/dist/index.js.map +1 -1
  32. package/{lib → dist}/utils.d.ts +2 -1
  33. package/dist/utils.js +145 -0
  34. package/dist/utils.js.map +1 -0
  35. package/jest.config.js +31 -5
  36. package/package.json +36 -32
  37. package/src/Entity.ts +229 -129
  38. package/src/Entity.types.ts +37 -57
  39. package/src/EntityWeakCache.ts +8 -6
  40. package/src/HttpRequester.ts +268 -31
  41. package/src/Nymph.ts +203 -96
  42. package/src/Nymph.types.ts +98 -2
  43. package/src/PubSub.ts +264 -181
  44. package/src/PubSub.types.ts +33 -19
  45. package/src/entityRefresh.ts +6 -6
  46. package/src/index.ts +10 -10
  47. package/src/utils.ts +67 -14
  48. package/tsconfig.json +7 -4
  49. package/typedoc.json +4 -0
  50. package/dist/index.js.LICENSE.txt +0 -8
  51. package/lib/Entity.d.ts +0 -51
  52. package/lib/Entity.js.map +0 -1
  53. package/lib/Entity.types.d.ts +0 -65
  54. package/lib/Entity.types.js +0 -3
  55. package/lib/EntityWeakCache.js.map +0 -1
  56. package/lib/HttpRequester.js +0 -190
  57. package/lib/HttpRequester.js.map +0 -1
  58. package/lib/Nymph.js.map +0 -1
  59. package/lib/Nymph.types.d.ts +0 -98
  60. package/lib/Nymph.types.js +0 -3
  61. package/lib/Nymph.types.js.map +0 -1
  62. package/lib/PubSub.js.map +0 -1
  63. package/lib/PubSub.types.js +0 -3
  64. package/lib/entityRefresh.js.map +0 -1
  65. package/lib/index.d.ts +0 -13
  66. package/lib/index.js +0 -34
  67. package/lib/index.js.map +0 -1
  68. package/lib/utils.js +0 -86
  69. package/lib/utils.js.map +0 -1
  70. package/webpack.config.js +0 -28
  71. /package/{lib → dist}/Entity.types.js.map +0 -0
  72. /package/{lib → dist}/PubSub.types.js.map +0 -0
@@ -0,0 +1,227 @@
1
+ import { EntityConstructor, EntityInterface } from './Entity.types.js';
2
+ export type NymphOptions = {
3
+ /**
4
+ * The URL of your Nymph REST server.
5
+ */
6
+ restUrl: string;
7
+ /**
8
+ * The URL of your Nymph PubSub server.
9
+ */
10
+ pubsubUrl?: string;
11
+ /**
12
+ * A fetch implementation.
13
+ */
14
+ fetch?: WindowOrWorkerGlobalScope['fetch'];
15
+ /**
16
+ * A WebSocket implementation.
17
+ */
18
+ WebSocket?: typeof WebSocket;
19
+ /**
20
+ * Return `null` or empty array instead of error when entity/ies not found.
21
+ */
22
+ returnNullOnNotFound?: boolean;
23
+ /**
24
+ * Whether to not output status messages to the console.
25
+ */
26
+ noConsole?: boolean;
27
+ /**
28
+ * Don't automatically try to connect to PubSub server.
29
+ */
30
+ noAutoconnect?: boolean;
31
+ /**
32
+ * Use a WeakRef based cache of entities.
33
+ *
34
+ * This ensures all entities returned are the same instance if they have the
35
+ * same class and GUID. This also means that whenever an entity is returned
36
+ * from the server, the single instance in memory will be refreshed. This
37
+ * could have annoying results, like destroying dirty data (the dreaded
38
+ * triple-D).
39
+ *
40
+ * This could also be a potential source of memory leaks. Although the
41
+ * entities themselves are referenced weakly so they get garbage collected,
42
+ * the GUID used as a key and the WeakRef object itself are not weak
43
+ * references, so not destroyed when the instance is garbage collected.
44
+ *
45
+ * However, even with these caveats, this might help you if you have a big app
46
+ * with the same entities stored in several different places in memory. This
47
+ * can help to synchronize them correctly and avoid data conflicts.
48
+ */
49
+ weakCache?: boolean;
50
+ /**
51
+ * Whether to renew tokens when a request is made.
52
+ *
53
+ * If you turn this off, the client will request that the server not renew an
54
+ * authentication token, even if it is within the renewal time of the
55
+ * expiration date.
56
+ *
57
+ * This defaults to true.
58
+ */
59
+ renewTokens?: boolean;
60
+ };
61
+ export type EventType = 'request' | 'response';
62
+ export type RequestCallback = (url: string, options: RequestInit) => void;
63
+ export type ResponseCallback = (response: Response, text: string) => void;
64
+ export type Options<T extends EntityConstructor = EntityConstructor> = {
65
+ /**
66
+ * The Entity class to query.
67
+ */
68
+ class: T;
69
+ /**
70
+ * The limit of entities to be returned. Not needed when using `getEntity`, as
71
+ * it always returns only one.
72
+ */
73
+ limit?: number;
74
+ /**
75
+ * The offset from the first matching entity, in order, to start retrieving.
76
+ */
77
+ offset?: number;
78
+ /**
79
+ * If true, entities will be retrieved from newest to oldest/largest to
80
+ * smallest (with regard to `sort`).
81
+ */
82
+ reverse?: boolean;
83
+ /**
84
+ * How to sort the entities. Should be "cdate", "mdate", the name of a
85
+ * property, or null.
86
+ */
87
+ sort?: 'cdate' | 'mdate' | string | null;
88
+ /**
89
+ * What to return, the entities with their data, just the GUIDs, or just a
90
+ * count.
91
+ */
92
+ return?: 'entity' | 'guid' | 'count';
93
+ /**
94
+ * If true, Nymph will skip the cache and retrieve the entity from the DB.
95
+ */
96
+ skipCache?: boolean;
97
+ /**
98
+ * The level(s) of access control requested.
99
+ *
100
+ * Limiting the access control can significantly improve the performance of
101
+ * the query.
102
+ */
103
+ acRequest?: TilmeldAccessRequest;
104
+ };
105
+ export type Clause<C> = C | Exclude<C, undefined>[];
106
+ export type OrWithTime<T> = T | [string, null, string];
107
+ type PrimitiveSelector = {
108
+ guid?: string;
109
+ '!guid'?: PrimitiveSelector['guid'];
110
+ tag?: string;
111
+ '!tag'?: PrimitiveSelector['tag'];
112
+ defined?: string;
113
+ '!defined'?: PrimitiveSelector['defined'];
114
+ truthy?: string;
115
+ '!truthy'?: PrimitiveSelector['truthy'];
116
+ equal?: [string, any];
117
+ '!equal'?: PrimitiveSelector['equal'];
118
+ contain?: [string, any];
119
+ '!contain'?: PrimitiveSelector['contain'];
120
+ search?: [string, string];
121
+ '!search'?: PrimitiveSelector['search'];
122
+ match?: [string, string];
123
+ '!match'?: PrimitiveSelector['match'];
124
+ imatch?: [string, string];
125
+ '!imatch'?: PrimitiveSelector['imatch'];
126
+ like?: [string, string];
127
+ '!like'?: PrimitiveSelector['like'];
128
+ ilike?: [string, string];
129
+ '!ilike'?: PrimitiveSelector['ilike'];
130
+ gt?: [string, number];
131
+ '!gt'?: PrimitiveSelector['gt'];
132
+ gte?: [string, number];
133
+ '!gte'?: PrimitiveSelector['gte'];
134
+ lt?: [string, number];
135
+ '!lt'?: PrimitiveSelector['lt'];
136
+ lte?: [string, number];
137
+ '!lte'?: PrimitiveSelector['lte'];
138
+ ref?: [string, EntityInterface | string];
139
+ '!ref'?: PrimitiveSelector['ref'];
140
+ qref?: [string, [Options, ...PrimitiveSelector[]]];
141
+ '!qref'?: PrimitiveSelector['qref'];
142
+ selector?: PrimitiveSelector;
143
+ '!selector'?: PrimitiveSelector['selector'];
144
+ };
145
+ export type Selector = {
146
+ type: '&' | '|' | '!&' | '!|';
147
+ guid?: Clause<PrimitiveSelector['guid']>;
148
+ '!guid'?: Clause<PrimitiveSelector['guid']>;
149
+ tag?: Clause<PrimitiveSelector['tag']>;
150
+ '!tag'?: Clause<PrimitiveSelector['tag']>;
151
+ defined?: Clause<PrimitiveSelector['defined']>;
152
+ '!defined'?: Clause<PrimitiveSelector['defined']>;
153
+ truthy?: Clause<PrimitiveSelector['truthy']>;
154
+ '!truthy'?: Clause<PrimitiveSelector['truthy']>;
155
+ equal?: Clause<OrWithTime<PrimitiveSelector['equal']>>;
156
+ '!equal'?: Clause<OrWithTime<PrimitiveSelector['equal']>>;
157
+ contain?: Clause<OrWithTime<PrimitiveSelector['contain']>>;
158
+ '!contain'?: Clause<OrWithTime<PrimitiveSelector['contain']>>;
159
+ search?: Clause<PrimitiveSelector['search']>;
160
+ '!search'?: Clause<PrimitiveSelector['search']>;
161
+ match?: Clause<PrimitiveSelector['match']>;
162
+ '!match'?: Clause<PrimitiveSelector['match']>;
163
+ imatch?: Clause<PrimitiveSelector['imatch']>;
164
+ '!imatch'?: Clause<PrimitiveSelector['imatch']>;
165
+ like?: Clause<PrimitiveSelector['like']>;
166
+ '!like'?: Clause<PrimitiveSelector['like']>;
167
+ ilike?: Clause<PrimitiveSelector['ilike']>;
168
+ '!ilike'?: Clause<PrimitiveSelector['ilike']>;
169
+ gt?: Clause<OrWithTime<PrimitiveSelector['gt']>>;
170
+ '!gt'?: Clause<OrWithTime<PrimitiveSelector['gt']>>;
171
+ gte?: Clause<OrWithTime<PrimitiveSelector['gte']>>;
172
+ '!gte'?: Clause<OrWithTime<PrimitiveSelector['gte']>>;
173
+ lt?: Clause<OrWithTime<PrimitiveSelector['lt']>>;
174
+ '!lt'?: Clause<OrWithTime<PrimitiveSelector['lt']>>;
175
+ lte?: Clause<OrWithTime<PrimitiveSelector['lte']>>;
176
+ '!lte'?: Clause<OrWithTime<PrimitiveSelector['lte']>>;
177
+ ref?: Clause<PrimitiveSelector['ref']>;
178
+ '!ref'?: Clause<PrimitiveSelector['ref']>;
179
+ qref?: Clause<[string, [Options, ...Selector[]]]>;
180
+ '!qref'?: Selector['qref'];
181
+ selector?: Clause<Selector>;
182
+ '!selector'?: Selector['selector'];
183
+ };
184
+ export declare enum TilmeldAccessRequest {
185
+ /**
186
+ * The default level, any possible entity readable by the user.
187
+ *
188
+ * This is the same as or-ing together all of the levels listed below.
189
+ */
190
+ ALL_LEVELS = 0,
191
+ /**
192
+ * Owned by and accessible to the user.
193
+ *
194
+ * This is always enabled, so not including it has no effect. It's here to
195
+ * allow the selection of _only_ user owned entities.
196
+ */
197
+ USER_OWNED = 1,
198
+ /**
199
+ * Owned by and accessible to the user's primary group.
200
+ */
201
+ PRIMARY_GROUP_OWNED = 2,
202
+ /**
203
+ * Owned by and accessible to one of the user's secondary groups.
204
+ */
205
+ SECONDARY_GROUP_OWNED = 4,
206
+ /**
207
+ * The user is listed in an access control list.
208
+ */
209
+ USER_ACCESSIBLE = 8,
210
+ /**
211
+ * The user's primary group is listed in an access control list.
212
+ */
213
+ PRIMARY_GROUP_ACCESSIBLE = 16,
214
+ /**
215
+ * One of the user's secondary groups is listed in an access control list.
216
+ */
217
+ SECONDARY_GROUP_ACCESSIBLE = 32,
218
+ /**
219
+ * The entity is accessible to any user.
220
+ */
221
+ OTHER_ACCESSIBLE = 64,
222
+ /**
223
+ * The entity is not owned by anyone.
224
+ */
225
+ UNOWNED = 128
226
+ }
227
+ export {};
@@ -0,0 +1,45 @@
1
+ export var TilmeldAccessRequest;
2
+ (function (TilmeldAccessRequest) {
3
+ /**
4
+ * The default level, any possible entity readable by the user.
5
+ *
6
+ * This is the same as or-ing together all of the levels listed below.
7
+ */
8
+ TilmeldAccessRequest[TilmeldAccessRequest["ALL_LEVELS"] = 0] = "ALL_LEVELS";
9
+ /**
10
+ * Owned by and accessible to the user.
11
+ *
12
+ * This is always enabled, so not including it has no effect. It's here to
13
+ * allow the selection of _only_ user owned entities.
14
+ */
15
+ TilmeldAccessRequest[TilmeldAccessRequest["USER_OWNED"] = 1] = "USER_OWNED";
16
+ /**
17
+ * Owned by and accessible to the user's primary group.
18
+ */
19
+ TilmeldAccessRequest[TilmeldAccessRequest["PRIMARY_GROUP_OWNED"] = 2] = "PRIMARY_GROUP_OWNED";
20
+ /**
21
+ * Owned by and accessible to one of the user's secondary groups.
22
+ */
23
+ TilmeldAccessRequest[TilmeldAccessRequest["SECONDARY_GROUP_OWNED"] = 4] = "SECONDARY_GROUP_OWNED";
24
+ /**
25
+ * The user is listed in an access control list.
26
+ */
27
+ TilmeldAccessRequest[TilmeldAccessRequest["USER_ACCESSIBLE"] = 8] = "USER_ACCESSIBLE";
28
+ /**
29
+ * The user's primary group is listed in an access control list.
30
+ */
31
+ TilmeldAccessRequest[TilmeldAccessRequest["PRIMARY_GROUP_ACCESSIBLE"] = 16] = "PRIMARY_GROUP_ACCESSIBLE";
32
+ /**
33
+ * One of the user's secondary groups is listed in an access control list.
34
+ */
35
+ TilmeldAccessRequest[TilmeldAccessRequest["SECONDARY_GROUP_ACCESSIBLE"] = 32] = "SECONDARY_GROUP_ACCESSIBLE";
36
+ /**
37
+ * The entity is accessible to any user.
38
+ */
39
+ TilmeldAccessRequest[TilmeldAccessRequest["OTHER_ACCESSIBLE"] = 64] = "OTHER_ACCESSIBLE";
40
+ /**
41
+ * The entity is not owned by anyone.
42
+ */
43
+ TilmeldAccessRequest[TilmeldAccessRequest["UNOWNED"] = 128] = "UNOWNED";
44
+ })(TilmeldAccessRequest || (TilmeldAccessRequest = {}));
45
+ //# sourceMappingURL=Nymph.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Nymph.types.js","sourceRoot":"","sources":["../src/Nymph.types.ts"],"names":[],"mappings":"AAoOA,MAAM,CAAN,IAAY,oBA0CX;AA1CD,WAAY,oBAAoB;IAC9B;;;;OAIG;IACH,2EAAc,CAAA;IACd;;;;;OAKG;IACH,2EAAc,CAAA;IACd;;OAEG;IACH,6FAAuB,CAAA;IACvB;;OAEG;IACH,iGAAyB,CAAA;IACzB;;OAEG;IACH,qFAAmB,CAAA;IACnB;;OAEG;IACH,wGAA6B,CAAA;IAC7B;;OAEG;IACH,4GAA+B,CAAA;IAC/B;;OAEG;IACH,wFAAqB,CAAA;IACrB;;OAEG;IACH,uEAAa,CAAA;AACf,CAAC,EA1CW,oBAAoB,KAApB,oBAAoB,QA0C/B"}
@@ -1,9 +1,12 @@
1
- import Nymph from './Nymph';
2
- import { NymphOptions, Options, Selector } from './Nymph.types';
3
- import { EntityConstructor, EntityInterface } from './Entity.types';
4
- import { PubSubCallbacks, PubSubConnectCallback, PubSubCountCallback, PubSubDisconnectCallback, PubSubEventType, PubSubRejectCallback, PubSubResolveCallback, PubSubSubscribable, PubSubUpdate } from './PubSub.types';
1
+ import Nymph from './Nymph.js';
2
+ import type { NymphOptions, Options, Selector } from './Nymph.types.js';
3
+ import type { EntityInstanceType } from './Entity.js';
4
+ import type { EntityConstructor, EntityInterface } from './Entity.types.js';
5
+ import type { PubSubCallbacks, PubSubConnectCallback, PubSubCountCallback, PubSubDisconnectCallback, PubSubEventType, PubSubRejectCallback, PubSubResolveCallback, PubSubErrorCallback, PubSubSubscribable, PubSubUpdate } from './PubSub.types.js';
5
6
  export default class PubSub {
6
7
  private nymph;
8
+ private authToken;
9
+ private switchToken;
7
10
  private connection;
8
11
  private waitForConnectionTimeout;
9
12
  private pubsubUrl;
@@ -11,16 +14,17 @@ export default class PubSub {
11
14
  private subscriptions;
12
15
  private connectCallbacks;
13
16
  private disconnectCallbacks;
17
+ private errorCallbacks;
14
18
  private noConsole;
15
19
  constructor(nymphOptions: NymphOptions, nymph: Nymph);
16
20
  subscribeEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
17
21
  return: 'guid';
18
22
  }, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<string[]>>;
19
- subscribeEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<ReturnType<T['factorySync']>[]>>;
23
+ subscribeEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<EntityInstanceType<T>[]>>;
20
24
  subscribeEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
21
25
  return: 'guid';
22
26
  }, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<string | null>>;
23
- subscribeEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<ReturnType<T['factorySync']> | null>>;
27
+ subscribeEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<EntityInstanceType<T> | null>>;
24
28
  subscribeUID(name: string): (resolve?: PubSubResolveCallback<number> | undefined, reject?: PubSubRejectCallback | undefined, count?: PubSubCountCallback | undefined) => {
25
29
  unsubscribe: () => void;
26
30
  };
@@ -34,6 +38,8 @@ export default class PubSub {
34
38
  private _onclose;
35
39
  private _send;
36
40
  isConnectionOpen(): boolean;
41
+ isConnectionConnecting(): boolean;
42
+ isConnection(): boolean;
37
43
  private _subscribeQuery;
38
44
  private _subscribeUID;
39
45
  private _sendQuery;
@@ -44,10 +50,10 @@ export default class PubSub {
44
50
  private _unsubscribeUID;
45
51
  private _sendUnQuery;
46
52
  private _sendUnUID;
47
- updateArray(oldArr: EntityInterface[], update: PubSubUpdate<EntityInterface[]>): void;
48
- on<T extends PubSubEventType>(event: T, callback: T extends 'connect' ? PubSubConnectCallback : T extends 'disconnect' ? PubSubDisconnectCallback : never): () => boolean;
49
- off<T extends PubSubEventType>(event: T, callback: T extends 'connect' ? PubSubConnectCallback : T extends 'disconnect' ? PubSubDisconnectCallback : never): boolean;
50
- setToken(token: string | null): void;
53
+ updateArray(current: EntityInterface[], update: PubSubUpdate<EntityInterface[]>): void;
54
+ on<T extends PubSubEventType>(event: T, callback: T extends 'connect' ? PubSubConnectCallback : T extends 'disconnect' ? PubSubDisconnectCallback : T extends 'error' ? PubSubErrorCallback : never): () => boolean;
55
+ off<T extends PubSubEventType>(event: T, callback: T extends 'connect' ? PubSubConnectCallback : T extends 'disconnect' ? PubSubDisconnectCallback : T extends 'error' ? PubSubErrorCallback : never): boolean;
56
+ authenticate(authToken: string | null, switchToken?: string | null): void;
51
57
  }
52
58
  export declare class PubSubSubscription<T> {
53
59
  query: string;