@salesforce/lds-runtime-bridge 1.293.0 → 1.294.0

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.
@@ -2914,6 +2914,7 @@ function buildQuery(config) {
2914
2914
  ${predicates.sql}
2915
2915
  ${orderBy.sql}
2916
2916
  LIMIT ?
2917
+ OFFSET ?
2917
2918
  `
2918
2919
  .split('\n')
2919
2920
  .map((line) => line.trim())
@@ -2926,6 +2927,7 @@ function buildQuery(config) {
2926
2927
  ...predicates.bindings,
2927
2928
  // limit binding
2928
2929
  config.limit || 10,
2930
+ config.offset || 0,
2929
2931
  ];
2930
2932
  return { sql: sql.trim(), bindings };
2931
2933
  }
@@ -3070,32 +3072,6 @@ async function readIngestionTimestampForKey(key, query) {
3070
3072
  return ingestionTimestamp;
3071
3073
  }
3072
3074
 
3073
- // Code lifted from https://github.com/MaxArt2501/base64-js/blob/master/base64.js
3074
- // base64 character set, plus padding character (=)
3075
- const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
3076
- function btoaPolyfill(input) {
3077
- let bitmap, a, b, c;
3078
- let result = '', i = 0;
3079
- const rest = input.length % 3; // To determine the final padding
3080
- for (; i < input.length;) {
3081
- if ((a = input.charCodeAt(i++)) > 255 ||
3082
- (b = input.charCodeAt(i++)) > 255 ||
3083
- (c = input.charCodeAt(i++)) > 255) {
3084
- throw new TypeError('Failed base64ToAscii encoding: The string to be encoded contains characters outside of the Latin1 range. ' +
3085
- input);
3086
- }
3087
- bitmap = (a << 16) | (b << 8) | c;
3088
- result +=
3089
- b64.charAt((bitmap >> 18) & 63) +
3090
- b64.charAt((bitmap >> 12) & 63) +
3091
- b64.charAt((bitmap >> 6) & 63) +
3092
- b64.charAt(bitmap & 63);
3093
- }
3094
- // If there's need of padding, replace the last 'A's with equal signs
3095
- return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
3096
- }
3097
- const base64encode = typeof btoa === 'function' ? btoa : btoaPolyfill;
3098
-
3099
3075
  function findSpanningField(name) {
3100
3076
  return (field) => {
3101
3077
  return (field.apiName === name ||
@@ -3242,13 +3218,101 @@ function scopeToPredicates(scope = '', settings) {
3242
3218
  ];
3243
3219
  }
3244
3220
 
3221
+ // Code lifted from https://github.com/MaxArt2501/base64-js/blob/master/base64.js
3222
+ // base64 character set, plus padding character (=)
3223
+ const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
3224
+ const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
3225
+ function btoaPolyfill(input) {
3226
+ let bitmap, a, b, c;
3227
+ let result = '', i = 0;
3228
+ const rest = input.length % 3; // To determine the final padding
3229
+ for (; i < input.length;) {
3230
+ if ((a = input.charCodeAt(i++)) > 255 ||
3231
+ (b = input.charCodeAt(i++)) > 255 ||
3232
+ (c = input.charCodeAt(i++)) > 255) {
3233
+ throw new TypeError('Failed base64ToAscii encoding: The string to be encoded contains characters outside of the Latin1 range. ' +
3234
+ input);
3235
+ }
3236
+ bitmap = (a << 16) | (b << 8) | c;
3237
+ result +=
3238
+ b64.charAt((bitmap >> 18) & 63) +
3239
+ b64.charAt((bitmap >> 12) & 63) +
3240
+ b64.charAt((bitmap >> 6) & 63) +
3241
+ b64.charAt(bitmap & 63);
3242
+ }
3243
+ // If there's need of padding, replace the last 'A's with equal signs
3244
+ return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
3245
+ }
3246
+ function atobPolyfill(data) {
3247
+ // atob can work with strings with whitespaces, even inside the encoded part,
3248
+ // but only \t, \n, \f, \r and ' ', which can be stripped.
3249
+ let string = String(data).replace(/[\t\n\f\r ]+/g, '');
3250
+ if (!b64re.test(string))
3251
+ throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
3252
+ // Adding the padding if missing, for semplicity
3253
+ string += '=='.slice(2 - (string.length & 3));
3254
+ var bitmap, result = '', r1, r2, i = 0;
3255
+ for (; i < string.length;) {
3256
+ bitmap =
3257
+ (b64.indexOf(string.charAt(i++)) << 18) |
3258
+ (b64.indexOf(string.charAt(i++)) << 12) |
3259
+ ((r1 = b64.indexOf(string.charAt(i++))) << 6) |
3260
+ (r2 = b64.indexOf(string.charAt(i++)));
3261
+ result +=
3262
+ r1 === 64
3263
+ ? String.fromCharCode((bitmap >> 16) & 255)
3264
+ : r2 === 64
3265
+ ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
3266
+ : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
3267
+ }
3268
+ return result;
3269
+ }
3270
+ const base64encode = typeof btoa === 'function' ? btoa : btoaPolyfill;
3271
+ const base64decode = typeof atob === 'function' ? atob : atobPolyfill;
3272
+
3273
+ function cursorResolver(source) {
3274
+ return encodeV1Cursor(source.index);
3275
+ }
3276
+ function pageInfoResolver(source) {
3277
+ if (source.length === 0) {
3278
+ return {
3279
+ startCursor: null,
3280
+ endCursor: null,
3281
+ };
3282
+ }
3283
+ let startIndex = source[0].index;
3284
+ let endIndex = source[source.length - 1].index;
3285
+ return {
3286
+ startCursor: encodeV1Cursor(startIndex),
3287
+ endCursor: encodeV1Cursor(endIndex),
3288
+ };
3289
+ }
3290
+ function pageResultCountResolver(source) {
3291
+ return source.length;
3292
+ }
3293
+ function encodeV1Cursor(index) {
3294
+ return base64encode(`v1:${index}`);
3295
+ }
3296
+ const cursorRegex = /^v1:(?<index>\d+)$/;
3297
+ function decodeV1Cursor(base64cursor) {
3298
+ const cursor = base64decode(base64cursor);
3299
+ if (!cursor) {
3300
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
3301
+ throw new Error('Unable to parse cursor');
3302
+ }
3303
+ const found = cursor.match(cursorRegex);
3304
+ if (!found || !found.groups) {
3305
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
3306
+ throw new Error('Unable to parse cursor');
3307
+ }
3308
+ return Number(found.groups.index);
3309
+ }
3310
+
3245
3311
  /*
3246
3312
  resolves connections...
3247
3313
  */
3248
3314
  async function connectionResolver(obj, args, context, info) {
3249
- let { recordRepresentation: parentRecord, ingestionTimestamp } = obj;
3250
- if (!ingestionTimestamp)
3251
- ingestionTimestamp = 0;
3315
+ let { recordRepresentation: parentRecord, ingestionTimestamp = 0 } = obj;
3252
3316
  if (!parentRecord && excludeStaleRecordsGate.isOpen({ fallback: false })) {
3253
3317
  // at our record query we fetch each ingestion time stamp and pass it down to each lower resolver to query against
3254
3318
  ingestionTimestamp = await fetchIngestionTimeStampFromDatabase(info.fieldName, info, args, context.query);
@@ -3277,6 +3341,10 @@ async function connectionResolver(obj, args, context, info) {
3277
3341
  ];
3278
3342
  const scopeJoins = scopeToJoins(args.scope, context.settings);
3279
3343
  joins.push(...scopeJoins);
3344
+ let offset = 0;
3345
+ if (args.after) {
3346
+ offset = decodeV1Cursor(args.after) + 1;
3347
+ }
3280
3348
  // Alias starts as entity's ApiName
3281
3349
  const queryConfig = {
3282
3350
  alias,
@@ -3284,18 +3352,20 @@ async function connectionResolver(obj, args, context, info) {
3284
3352
  predicates,
3285
3353
  orderBy: orderByToPredicate(args.orderBy, alias, alias, context.objectInfos),
3286
3354
  limit: args.first,
3355
+ offset: offset,
3287
3356
  ingestionTimestamp,
3288
3357
  };
3289
3358
  const { sql, bindings } = buildQuery(queryConfig);
3290
3359
  const results = await query(sql, bindings);
3291
3360
  //map each sql result with the ingestion timestamp to pass it down a level
3292
3361
  return results.rows
3293
- .map((row) => row[0])
3294
- .map((record, index) => {
3362
+ .map((row) => parse(row[0]))
3363
+ .map((recordRepresentation, index) => {
3364
+ context.seenRecordIds.add(recordRepresentation.id);
3295
3365
  return {
3296
- record,
3366
+ recordRepresentation,
3297
3367
  ingestionTimestamp,
3298
- index,
3368
+ index: index + offset,
3299
3369
  };
3300
3370
  });
3301
3371
  }
@@ -3459,10 +3529,10 @@ function addResolversToSchema(schema, polyFields) {
3459
3529
  field.resolve = passThroughResolver;
3460
3530
  break;
3461
3531
  case 'pageInfo':
3462
- field.resolve = function (_value, _args, _context, _info) {
3463
- // TODO [W-12390939]: implement resolver for PageInfo
3464
- return {};
3465
- };
3532
+ field.resolve = pageInfoResolver;
3533
+ break;
3534
+ case 'pageResultCount':
3535
+ field.resolve = pageResultCountResolver;
3466
3536
  break;
3467
3537
  default:
3468
3538
  field.resolve = defaultFieldResolver;
@@ -3485,17 +3555,10 @@ function addResolversToSchema(schema, polyFields) {
3485
3555
  // }
3486
3556
  for (const field of fields) {
3487
3557
  if (field.name === 'node') {
3488
- field.resolve = function nodeResolver(obj, _args, { seenRecordIds }) {
3489
- const { record, ingestionTimestamp } = obj;
3490
- const recordRepresentation = parse(record);
3491
- seenRecordIds.add(recordRepresentation.id);
3492
- return { recordRepresentation, ingestionTimestamp };
3493
- };
3558
+ field.resolve = passThroughResolver;
3494
3559
  }
3495
3560
  else if (field.name === 'cursor') {
3496
- field.resolve = function ({ index }) {
3497
- return base64encode(`v1:${index}`);
3498
- };
3561
+ field.resolve = cursorResolver;
3499
3562
  }
3500
3563
  }
3501
3564
  }
@@ -4172,4 +4235,4 @@ function ldsRuntimeBridge() {
4172
4235
  }
4173
4236
 
4174
4237
  export { ldsRuntimeBridge as default };
4175
- // version: 1.293.0-5fab18553
4238
+ // version: 1.294.0-06a44f23f
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-bridge",
3
- "version": "1.293.0",
3
+ "version": "1.294.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS runtime for bridge.app.",
6
6
  "main": "dist/ldsRuntimeBridge.js",
@@ -34,17 +34,17 @@
34
34
  "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-runtime-bridge"
35
35
  },
36
36
  "dependencies": {
37
- "@salesforce/lds-adapters-uiapi": "^1.293.0",
38
- "@salesforce/lds-instrumentation": "^1.293.0",
37
+ "@salesforce/lds-adapters-uiapi": "^1.294.0",
38
+ "@salesforce/lds-instrumentation": "^1.294.0",
39
39
  "@salesforce/user": "0.0.21",
40
40
  "o11y": "250.7.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@salesforce/lds-drafts-adapters-uiapi": "^1.293.0",
44
- "@salesforce/lds-network-aura": "^1.293.0",
45
- "@salesforce/lds-runtime-aura": "^1.293.0",
46
- "@salesforce/lds-store-nimbus": "^1.293.0",
47
- "@salesforce/nimbus-plugin-lds": "^1.293.0",
43
+ "@salesforce/lds-drafts-adapters-uiapi": "^1.294.0",
44
+ "@salesforce/lds-network-aura": "^1.294.0",
45
+ "@salesforce/lds-runtime-aura": "^1.294.0",
46
+ "@salesforce/lds-store-nimbus": "^1.294.0",
47
+ "@salesforce/nimbus-plugin-lds": "^1.294.0",
48
48
  "babel-plugin-dynamic-import-node": "^2.3.3"
49
49
  },
50
50
  "luvioBundlesize": [