pict-section-recordset 1.0.8 → 1.0.10

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-recordset",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Pict dynamic record set management views",
5
5
  "main": "source/Pict-Section-RecordSet.js",
6
6
  "directories": {
@@ -2,20 +2,8 @@
2
2
  const libRecordSetProviderBase = require('./RecordSet-RecordProvider-Base.js');
3
3
 
4
4
  /**
5
- * @typedef {(error?: Error, result?: any) => void} RestClientCallback
6
- *
7
5
  * @typedef {import('./RecordSet-RecordProvider-Base.js').RecordSetFilter} RecordSetFilter
8
6
  * @typedef {import('./RecordSet-RecordProvider-Base.js').RecordSetResult} RecordSetResult
9
- *
10
- * @typedef {{
11
- * getJSON(pOptionsOrURL: string | Record<string, any>, fCallback: RestClientCallback): void,
12
- * putJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
13
- * postJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
14
- * patchJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
15
- * headJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
16
- * delJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
17
- * getRawText(pOptionsOrURL: string | Record<string, any>, fCallback: RestClientCallback): void,
18
- * }} RestClient
19
7
  */
20
8
 
21
9
  /**
@@ -45,12 +33,6 @@ class RecordSetProvider extends libRecordSetProviderBase
45
33
  this._Schema = { };
46
34
  }
47
35
 
48
- /** @type {RestClient} */
49
- get restClient()
50
- {
51
- return this.fable.RestClient;
52
- }
53
-
54
36
  /**
55
37
  * @typedef {(error?: Error, result?: T) => void} RecordSetCallback
56
38
  * @template T = Record<string, any>
@@ -78,13 +60,13 @@ class RecordSetProvider extends libRecordSetProviderBase
78
60
  }
79
61
  return new Promise((resolve, reject) =>
80
62
  {
81
- this.restClient.getJSON(`${this.options.URLPrefix}${this.options.Entity}/${pIDOrGuid}`, (error, response, result) =>
63
+ this.entityProvider.getEntity(this.options.Entity, pIDOrGuid, (pError, pResult) =>
82
64
  {
83
- if (error)
65
+ if (pError)
84
66
  {
85
- return reject(error);
67
+ return reject(pError);
86
68
  }
87
- resolve(result);
69
+ resolve(pResult);
88
70
  });
89
71
  });
90
72
  }
@@ -106,13 +88,17 @@ class RecordSetProvider extends libRecordSetProviderBase
106
88
  }
107
89
  return new Promise((resolve, reject) =>
108
90
  {
109
- this.restClient.getJSON(`${this.options.URLPrefix}${this.options.Entity}s/FilteredTo/FBV~GUID${this.options.Entity}~EQ~${encodeURIComponent(pGuid)}`, (error, response, result) =>
91
+ this.entityProvider.getEntitySet(this.options.Entity, `FBV~GUID${this.options.Entity}~EQ~${encodeURIComponent(pGuid)}`, (pError, pResult) =>
110
92
  {
111
- if (error)
93
+ if (pError)
112
94
  {
113
- return reject(error);
95
+ return reject(pError);
96
+ }
97
+ if (pResult.length > 1)
98
+ {
99
+ this.pict.log.error(`Multiple ${this.options.Entity} records found for GUID ${pGuid}`, { Records: pResult });
114
100
  }
115
- resolve(result[0]);
101
+ resolve(pResult[0]);
116
102
  });
117
103
  });
118
104
  }
@@ -129,22 +115,21 @@ class RecordSetProvider extends libRecordSetProviderBase
129
115
  {
130
116
  throw new Error('Entity is not defined in the provider options.');
131
117
  }
118
+ const tmpEntity = pOptions.Entity || this.options.Entity;
132
119
  if (this.pict.LogNoisiness > 1)
133
120
  {
134
- this.pict.log.info(`Reading ${this.options.Entity} records`, { Options: pOptions });
121
+ this.pict.log.info(`Reading ${tmpEntity} records`, { Options: pOptions });
135
122
  }
136
- const filterString = pOptions.FilterString ? `/FilteredTo/${pOptions.FilterString}` : '';
137
- const pagination = `/${pOptions.Offset || 0}/${pOptions.PageSize || 250}`;
138
- //TODO: lite support / other variants?
139
123
  return new Promise((resolve, reject) =>
140
124
  {
141
- this.restClient.getJSON(`${this.options.URLPrefix}${this.options.Entity || pOptions.Entity}s${filterString}${pagination}`, (error, response, result) =>
125
+ // using a space here, otherwise you get a `//` in the URL which breaks some stuff
126
+ this.entityProvider.getEntitySetPage(tmpEntity, pOptions.FilterString ? pOptions.FilterString : ' ', pOptions.Offset || 0, pOptions.PageSize || 250, (pError, pResult) =>
142
127
  {
143
- if (error)
128
+ if (pError)
144
129
  {
145
- return reject(error);
130
+ return reject(pError);
146
131
  }
147
- resolve({ Records: result, Facets: { } });
132
+ resolve({ Records: pResult, Facets: { } });
148
133
  });
149
134
  });
150
135
  }
@@ -173,21 +158,21 @@ class RecordSetProvider extends libRecordSetProviderBase
173
158
  {
174
159
  throw new Error('Entity is not defined in the provider options.');
175
160
  }
161
+ const tmpEntity = pOptions.Entity || this.options.Entity;
176
162
  if (this.pict.LogNoisiness > 1)
177
163
  {
178
- this.pict.log.info(`Counting ${this.options.Entity} records`, { Options: pOptions });
164
+ this.pict.log.info(`Counting ${tmpEntity} records`, { Options: pOptions });
179
165
  }
180
- const filterString = pOptions.FilterString ? `/FilteredTo/${pOptions.FilterString}` : '';
181
166
  //TODO: lite support / other variants?
182
167
  return new Promise((resolve, reject) =>
183
168
  {
184
- this.restClient.getJSON(`${this.options.URLPrefix}${this.options.Entity || pOptions.Entity}s/Count${filterString}`, (error, response, result) =>
169
+ this.entityProvider.getEntitySetRecordCount(tmpEntity, pOptions.FilterString, (pError, pCount) =>
185
170
  {
186
- if (error)
171
+ if (pError)
187
172
  {
188
- return reject(error);
173
+ return reject(pError);
189
174
  }
190
- resolve(result);
175
+ resolve({ Count: pCount });
191
176
  });
192
177
  });
193
178
  }
@@ -201,11 +186,11 @@ class RecordSetProvider extends libRecordSetProviderBase
201
186
  {
202
187
  return new Promise((resolve, reject) =>
203
188
  {
204
- if (this.pict.LogNoisiness > 1)
205
- {
206
- this.pict.log.info(`Creating record ${this.options.Entity}`, { Record: pRecord });
207
- }
208
- this.restClient.postJSON({
189
+ if (this.pict.LogNoisiness > 1)
190
+ {
191
+ this.pict.log.info(`Creating record ${this.options.Entity}`, { Record: pRecord });
192
+ }
193
+ this.entityProvider.restClient.postJSON({
209
194
  url: `${this.options.URLPrefix}${this.options.Entity}`,
210
195
  body: pRecord,
211
196
  }, (error, response, result) =>
@@ -232,7 +217,7 @@ class RecordSetProvider extends libRecordSetProviderBase
232
217
  }
233
218
  return new Promise((resolve, reject) =>
234
219
  {
235
- this.restClient.putJSON({
220
+ this.entityProvider.restClient.putJSON({
236
221
  url: `${this.options.URLPrefix}${this.options.Entity}`,
237
222
  body: pRecord,
238
223
  }, (error, response, result) =>
@@ -259,7 +244,7 @@ class RecordSetProvider extends libRecordSetProviderBase
259
244
  }
260
245
  return new Promise((resolve, reject) =>
261
246
  {
262
- this.restClient.delJSON({
247
+ this.entityProvider.restClient.delJSON({
263
248
  url: `${this.options.URLPrefix}${this.options.Entity}/${pRecord[`ID${this.options.Entity}`]}`,
264
249
  body: pRecord,
265
250
  }, (error, response, result) =>
@@ -316,6 +301,16 @@ class RecordSetProvider extends libRecordSetProviderBase
316
301
  return pRecord;
317
302
  }
318
303
 
304
+ onBeforeInitialize()
305
+ {
306
+ /** @type {import('pict/types/source/Pict-Meadow-EntityProvider.js')} */
307
+ this.entityProvider = this.pict.instantiateServiceProviderWithoutRegistration('EntityProvider');
308
+ if (this.options.URLPrefix)
309
+ {
310
+ this.entityProvider.options.urlPrefix = this.options.URLPrefix;
311
+ }
312
+ }
313
+
319
314
  /**
320
315
  * @param {(error?: Error) => void} fCallback - The callback function.
321
316
  */
@@ -329,7 +324,7 @@ class RecordSetProvider extends libRecordSetProviderBase
329
324
  {
330
325
  return fCallback();
331
326
  }
332
- this.restClient.getJSON(`${this.options.URLPrefix}${this.options.Entity}/Schema`, (error, response, result) =>
327
+ this.entityProvider.restClient.getJSON(`${this.options.URLPrefix}${this.options.Entity}/Schema`, (error, response, result) =>
333
328
  {
334
329
  if (error)
335
330
  {
@@ -263,8 +263,24 @@ class viewRecordSetList extends libPictRecordSetRecordView
263
263
 
264
264
  //FIXME: short-term workaround to not blow up the tempplate rendering with way too many links
265
265
  const linkRangeStart = Math.max(0, tmpRecordListData.PageLinkBookmarks.Current - 10);
266
- const linkRangeEnd = Math.min(tmpRecordListData.PageLinks.length - 1, tmpRecordListData.PageLinkBookmarks.Current + 10);
266
+ const linkRangeEnd = Math.min(tmpRecordListData.PageLinks.length, tmpRecordListData.PageLinkBookmarks.Current + 10);
267
267
  tmpRecordListData.PageLinksLimited = tmpRecordListData.PageLinks.slice(linkRangeStart, linkRangeEnd);
268
+ if (linkRangeStart > 0)
269
+ {
270
+ tmpRecordListData.PageLinksLimited.unshift(
271
+ {
272
+ Page: 1,
273
+ URL:`#/PSRS/${tmpRecordListData.RecordSet}/List/${0}/${tmpRecordListData.PageSize}`
274
+ });
275
+ }
276
+ if (linkRangeEnd < tmpRecordListData.PageLinks.length)
277
+ {
278
+ tmpRecordListData.PageLinksLimited.push(
279
+ {
280
+ Page: tmpRecordListData.PageCount,
281
+ URL:`#/PSRS/${tmpRecordListData.RecordSet}/List/${(tmpRecordListData.PageCount - 1) * tmpRecordListData.PageSize}/${tmpRecordListData.PageSize}`
282
+ });
283
+ }
268
284
 
269
285
  tmpRecordListData.PageLinkBookmarks.Previous = tmpRecordListData.PageLinkBookmarks.Current - 1;
270
286
  tmpRecordListData.PageLinkBookmarks.Next = tmpRecordListData.PageLinkBookmarks.Current + 1;
@@ -1,19 +1,7 @@
1
1
  export = RecordSetProvider;
2
2
  /**
3
- * @typedef {(error?: Error, result?: any) => void} RestClientCallback
4
- *
5
3
  * @typedef {import('./RecordSet-RecordProvider-Base.js').RecordSetFilter} RecordSetFilter
6
4
  * @typedef {import('./RecordSet-RecordProvider-Base.js').RecordSetResult} RecordSetResult
7
- *
8
- * @typedef {{
9
- * getJSON(pOptionsOrURL: string | Record<string, any>, fCallback: RestClientCallback): void,
10
- * putJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
11
- * postJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
12
- * patchJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
13
- * headJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
14
- * delJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void,
15
- * getRawText(pOptionsOrURL: string | Record<string, any>, fCallback: RestClientCallback): void,
16
- * }} RestClient
17
5
  */
18
6
  /**
19
7
  * Class representing a data change detection provider for Pict dynamic forms.
@@ -24,8 +12,6 @@ declare class RecordSetProvider extends libRecordSetProviderBase {
24
12
  pict: any & import("pict");
25
13
  /** @type {Record<string, any>} */
26
14
  _Schema: Record<string, any>;
27
- /** @type {RestClient} */
28
- get restClient(): RestClient;
29
15
  /**
30
16
  * @typedef {(error?: Error, result?: T) => void} RecordSetCallback
31
17
  * @template T = Record<string, any>
@@ -78,6 +64,9 @@ declare class RecordSetProvider extends libRecordSetProviderBase {
78
64
  * @param {Record<string, any>} pRecord - The record to clone.
79
65
  */
80
66
  cloneRecord(pRecord: Record<string, any>): Promise<any>;
67
+ onBeforeInitialize(): void;
68
+ /** @type {import('pict/types/source/Pict-Meadow-EntityProvider.js')} */
69
+ entityProvider: import("pict/types/source/Pict-Meadow-EntityProvider.js");
81
70
  /**
82
71
  * @param {(error?: Error) => void} fCallback - The callback function.
83
72
  */
@@ -85,19 +74,9 @@ declare class RecordSetProvider extends libRecordSetProviderBase {
85
74
  getRecordSchema(): Promise<Record<string, any>>;
86
75
  }
87
76
  declare namespace RecordSetProvider {
88
- export { RestClientCallback, RecordSetFilter, RecordSetResult, RestClient };
77
+ export { RecordSetFilter, RecordSetResult };
89
78
  }
90
79
  import libRecordSetProviderBase = require("./RecordSet-RecordProvider-Base.js");
91
- type RestClientCallback = (error?: Error, result?: any) => void;
92
80
  type RecordSetFilter = import("./RecordSet-RecordProvider-Base.js").RecordSetFilter;
93
81
  type RecordSetResult = import("./RecordSet-RecordProvider-Base.js").RecordSetResult;
94
- type RestClient = {
95
- getJSON(pOptionsOrURL: string | Record<string, any>, fCallback: RestClientCallback): void;
96
- putJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void;
97
- postJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void;
98
- patchJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void;
99
- headJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void;
100
- delJSON(pOptions: Record<string, any>, fCallback: RestClientCallback): void;
101
- getRawText(pOptionsOrURL: string | Record<string, any>, fCallback: RestClientCallback): void;
102
- };
103
82
  //# sourceMappingURL=RecordSet-RecordProvider-MeadowEndpoints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RecordSet-RecordProvider-MeadowEndpoints.d.ts","sourceRoot":"","sources":["../../source/providers/RecordSet-RecordProvider-MeadowEndpoints.js"],"names":[],"mappings":";AAGA;;;;;;;;;;;;;;;GAeG;AAEH;;;GAGG;AACH;IAgBE,+CAA+C;IAC/C,MADW,GAAe,GAAG,OAAO,MAAM,CAAC,CAClC;IAET,kCAAkC;IAClC,SADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACZ;IAGnB,yBAAyB;IACzB,kBADW,UAAU,CAIpB;IAED;;;OAGG;IAEH;;;;OAIG;IACH,qBAFW,MAAM,GAAC,MAAM,gBA4BvB;IAED;;;;OAIG;IACH,uBAFW,MAAM,GAAC,MAAM,gBAuBvB;IA+CD;;;;OAIG;IACH,4BAFW,eAAe,gBAyBzB;IAED;;;;OAIG;IACH,sBAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAsB7B;IAED;;;;OAIG;IACH,sBAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAsB7B;IAED;;;;OAIG;IACH,sBAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAsB7B;IAED;;;;OAIG;IACH,sBAFW,MAAM,GAAC,MAAM,gBAKvB;IAaD;;;;OAIG;IACH,qBAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAK7B;IAcD;;OAEG;IAC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AC/C,MADW,GAAe,GAAG,OAAO,MAAM,CAAC,CAClC;IAET,kCAAkC;IAClC,SADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACZ;IAGnB;;;OAGG;IAEH;;;;OAIG;IACH,qBAFW,MAAM,GAAC,MAAM,gBA4BvB;IAED;;;;OAIG;IACH,uBAFW,MAAM,GAAC,MAAM,gBA2BvB;IA8CD;;;;OAIG;IACH,4BAFW,eAAe,gBAyBzB;IAED;;;;OAIG;IACH,sBAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAsB7B;IAED;;;;OAIG;IACH,sBAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAsB7B;IAED;;;;OAIG;IACH,sBAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAsB7B;IAED;;;;OAIG;IACH,sBAFW,MAAM,GAAC,MAAM,gBAKvB;IAaD;;;;OAIG;IACH,qBAFW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAK7B;IAcD,2BAQC;IANA,wEAAwE;IACxE,gBADW,OAAO,iDAAiD,CAAC,CAC2B;IAOhG;;OAEG;IACH,6BAFW,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,QA2BjC;IAED,gDAcC;CACD;;;;;uBAlWY,OAAO,oCAAoC,EAAE,eAAe;uBAC5D,OAAO,oCAAoC,EAAE,eAAe"}
@@ -1 +1 @@
1
- {"version":3,"file":"RecordSet-List.d.ts","sourceRoot":"","sources":["../../../source/views/list/RecordSet-List.js"],"names":[],"mappings":";AAyEA;IAOE;;;;;;;;MAQC;IAGF,uCAuBC;IAED,+DAuBC;IAWD,8CAGC;IAED,sDAkCC;IA9BA,iCAUC;IAsBF,iIAmIC;CAwBD"}
1
+ {"version":3,"file":"RecordSet-List.d.ts","sourceRoot":"","sources":["../../../source/views/list/RecordSet-List.js"],"names":[],"mappings":";AAyEA;IAOE;;;;;;;;MAQC;IAGF,uCAuBC;IAED,+DAuBC;IAWD,8CAGC;IAED,sDAkCC;IA9BA,iCAUC;IAsBF,iIAmJC;CAwBD"}