@reventlessdev/rescript-pulumi-aws 3.0.0-alpha.3 → 3.0.0-alpha.5
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.
|
@@ -388,25 +388,99 @@ export function request(ctx) {
|
|
|
388
388
|
`;
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
391
|
+
function pageWindowBudget(filtered) {
|
|
392
|
+
return `(` + filtered + ` ? (_first > 1000 ? _first : 1000) : _first + _from)`;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
let need = "(_backward ? _upTo : _first + _from)";
|
|
396
|
+
|
|
397
|
+
let listPageWindowBudget = `(parts.length > 0 ? (` + need + ` > 1000 ? ` + need + ` : 1000) : ` + need + `)`;
|
|
398
|
+
|
|
399
|
+
function cursorDecode(args) {
|
|
400
|
+
return `
|
|
401
|
+
let _window = null;
|
|
402
|
+
let _from = 0;
|
|
403
|
+
let _cursorPath = null;
|
|
404
|
+
if (` + args + `.after != null && ` + args + `.after !== '') {
|
|
405
|
+
const _c = JSON.parse(util.base64Decode(` + args + `.after));
|
|
406
|
+
_window = (_c.t !== undefined ? _c.t : _c.token) ?? null;
|
|
407
|
+
_from = _c.n !== undefined ? _c.n + 1 : 0;
|
|
408
|
+
_cursorPath = _c.p ?? 's';
|
|
409
|
+
}`;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
let cursorPathGuard = `
|
|
413
|
+
if (_cursorPath !== null && _cursorPath !== (_exempt ? 's' : 'q')) {
|
|
414
|
+
util.error('This cursor belongs to a different read of this list; restart from the first page.', 'CursorPathMismatch');
|
|
415
|
+
}`;
|
|
416
|
+
|
|
417
|
+
let listCursorPreamble = `
|
|
418
|
+
const _first = ctx.args.first ?? 50;
|
|
419
|
+
let _window = null;
|
|
420
|
+
let _from = 0;
|
|
421
|
+
let _cursorPath = null;
|
|
422
|
+
let _backward = false;
|
|
423
|
+
let _upTo = -1;
|
|
424
|
+
if (ctx.args.before != null && ctx.args.before !== '') {
|
|
425
|
+
const _c = JSON.parse(util.base64Decode(ctx.args.before));
|
|
426
|
+
_window = (_c.t !== undefined ? _c.t : _c.token) ?? null;
|
|
427
|
+
_cursorPath = _c.p ?? 's';
|
|
428
|
+
_backward = true;
|
|
429
|
+
_upTo = _c.n !== undefined ? _c.n : 0;
|
|
430
|
+
_from = (_upTo - _first) > 0 ? (_upTo - _first) : 0;
|
|
431
|
+
} else if (ctx.args.after != null && ctx.args.after !== '') {
|
|
432
|
+
const _c = JSON.parse(util.base64Decode(ctx.args.after));
|
|
433
|
+
_window = (_c.t !== undefined ? _c.t : _c.token) ?? null;
|
|
434
|
+
_from = _c.n !== undefined ? _c.n + 1 : 0;
|
|
435
|
+
_cursorPath = _c.p ?? 's';
|
|
436
|
+
}`;
|
|
437
|
+
|
|
438
|
+
function connectionPageResponse(pathExpr, bidirectionalOpt) {
|
|
439
|
+
let bidirectional = bidirectionalOpt !== undefined ? bidirectionalOpt : false;
|
|
440
|
+
let tag = pathExpr !== undefined ? `, p: ` + pathExpr : "";
|
|
441
|
+
let firstDecl = bidirectional ? "" : "\n const _first = ctx.args.first ?? 50;";
|
|
442
|
+
let slice = bidirectional ? `
|
|
443
|
+
const _rest = _backward ? items.slice(_from, _upTo) : items.slice(_from);
|
|
444
|
+
const _page = _backward ? _rest : _rest.slice(0, _first);
|
|
445
|
+
// A backward page was cut from ahead, so a next page provably exists — the one
|
|
446
|
+
// the caller came from — whatever this window's tail looks like.
|
|
447
|
+
const _more = _backward ? true : _rest.length > _first;` : `
|
|
448
|
+
const _rest = items.slice(_from);
|
|
449
|
+
const _page = _rest.slice(0, _first);
|
|
450
|
+
const _more = _rest.length > _first;`;
|
|
451
|
+
let hasPrevious = bidirectional ? "_from > 0" : "!!ctx.args.after";
|
|
452
|
+
return firstDecl + slice + `
|
|
453
|
+
const _next = ctx.result?.nextToken ?? null;
|
|
454
|
+
const _lastIndex = _page.length - 1;
|
|
455
|
+
// A row's cursor names its own position. The last row of a page that closes its
|
|
456
|
+
// window is the exception — no position follows it there, so it names the next
|
|
457
|
+
// window, or resuming from it answers blank.
|
|
458
|
+
const edges = _page.map((item, i) => ({
|
|
397
459
|
node: item,
|
|
398
|
-
cursor: util.base64Encode(JSON.stringify(
|
|
460
|
+
cursor: util.base64Encode(JSON.stringify(
|
|
461
|
+
(!_more && _next && i === _lastIndex)
|
|
462
|
+
? { t: _next, n: -1` + tag + ` }
|
|
463
|
+
: { t: _window, n: _from + i` + tag + ` }
|
|
464
|
+
)),
|
|
399
465
|
}));
|
|
400
|
-
|
|
466
|
+
// A window the filter emptied leaves no row to cut a cursor from; the token is
|
|
467
|
+
// the window's, so a client can step past it rather than restart.
|
|
468
|
+
const _boundary = _next ? util.base64Encode(JSON.stringify({ t: _next, n: -1` + tag + ` })) : null;
|
|
401
469
|
return {
|
|
402
470
|
edges,
|
|
403
471
|
pageInfo: {
|
|
404
|
-
hasNextPage: !!
|
|
405
|
-
hasPreviousPage:
|
|
406
|
-
startCursor: edges.length > 0 ? edges[0].cursor :
|
|
407
|
-
endCursor: edges.length > 0 ? edges[edges.length - 1].cursor :
|
|
472
|
+
hasNextPage: _more || !!_next,
|
|
473
|
+
hasPreviousPage: ` + hasPrevious + `,
|
|
474
|
+
startCursor: edges.length > 0 ? edges[0].cursor : _boundary,
|
|
475
|
+
endCursor: edges.length > 0 ? edges[edges.length - 1].cursor : _boundary,
|
|
408
476
|
},
|
|
409
|
-
}
|
|
477
|
+
};`;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
let indexConnectionResponseCode = `
|
|
481
|
+
export function response(ctx) {
|
|
482
|
+
if (ctx.error) util.error(ctx.error.message, ctx.error.type);
|
|
483
|
+
const items = ctx.result?.items ?? [];` + cursorDecode("ctx.args") + connectionPageResponse(undefined, undefined) + `
|
|
410
484
|
}`;
|
|
411
485
|
|
|
412
486
|
let indexBackwardPagingGuard = `
|
|
@@ -414,12 +488,8 @@ let indexBackwardPagingGuard = `
|
|
|
414
488
|
util.error('Backward pagination (last/before) is not supported on by-index connections; use first/after.', 'UnsupportedPagination');
|
|
415
489
|
}`;
|
|
416
490
|
|
|
417
|
-
let indexCursorPreamble = `
|
|
418
|
-
|
|
419
|
-
if (args.after != null && args.after !== '') {
|
|
420
|
-
const parsed = JSON.parse(util.base64Decode(args.after));
|
|
421
|
-
after = parsed.token ?? null;
|
|
422
|
-
}`;
|
|
491
|
+
let indexCursorPreamble = cursorDecode("args") + `
|
|
492
|
+
const _first = args.first ?? 50;`;
|
|
423
493
|
|
|
424
494
|
let indexReservedArgs = `key === 'first' || key === 'after' || key === 'last' || key === 'before' || key === 'includeRetired' || key === 'limit' || key === 'nextToken' || key === 'forward'`;
|
|
425
495
|
|
|
@@ -458,8 +528,8 @@ export function request(ctx) {
|
|
|
458
528
|
operation: 'Query',
|
|
459
529
|
query,
|
|
460
530
|
index: '` + index + `',
|
|
461
|
-
limit: (
|
|
462
|
-
nextToken:
|
|
531
|
+
limit: ` + (`(` + "expression" + ` ? (_first > 1000 ? _first : 1000) : _first + _from)`) + `,
|
|
532
|
+
nextToken: _window,
|
|
463
533
|
scanIndexForward: (args.forward ?? true)
|
|
464
534
|
};
|
|
465
535
|
if (expression) {
|
|
@@ -515,8 +585,8 @@ export function request(ctx) {
|
|
|
515
585
|
operation: 'Query',
|
|
516
586
|
query,
|
|
517
587
|
index: '` + index + `',
|
|
518
|
-
limit: (
|
|
519
|
-
nextToken:
|
|
588
|
+
limit: ` + (`(` + "expression" + ` ? (_first > 1000 ? _first : 1000) : _first + _from)`) + `,
|
|
589
|
+
nextToken: _window,
|
|
520
590
|
scanIndexForward: (args.forward ?? true)
|
|
521
591
|
};
|
|
522
592
|
if (expression) {
|
|
@@ -539,18 +609,17 @@ export function request(ctx) {
|
|
|
539
609
|
` + resultResponseCode + `
|
|
540
610
|
`;
|
|
541
611
|
|
|
542
|
-
function listAllItemsConnection(labelField, filterFieldsOpt, rangeFieldsOpt, sortFieldsOpt, requireAttribute, ownerField, elevatedGroupsOpt, retiredField, retiredValues) {
|
|
612
|
+
function listAllItemsConnection(labelField, filterFieldsOpt, rangeFieldsOpt, sortFieldsOpt, requireAttribute, ownerField, elevatedGroupsOpt, retiredField, retiredValues, ownerIndex, ownerIndexSortField) {
|
|
543
613
|
let filterFields = filterFieldsOpt !== undefined ? filterFieldsOpt : [];
|
|
544
614
|
let rangeFields = rangeFieldsOpt !== undefined ? rangeFieldsOpt : [];
|
|
545
615
|
let sortFields = sortFieldsOpt !== undefined ? sortFieldsOpt : [];
|
|
546
616
|
let elevatedGroups = elevatedGroupsOpt !== undefined ? elevatedGroupsOpt : [];
|
|
617
|
+
let ownerIndex$1 = Stdlib_Option.isSome(ownerField) ? ownerIndex : undefined;
|
|
547
618
|
let requireAttributeClause = requireAttribute !== undefined ? `
|
|
548
619
|
names['#` + requireAttribute + `'] = '` + requireAttribute + `';
|
|
549
620
|
parts.push('attribute_exists(#` + requireAttribute + `)');` : "";
|
|
550
|
-
let
|
|
551
|
-
|
|
552
|
-
let elevatedLiteral = elevatedGroups.map(g => `'` + g + `'`).join(", ");
|
|
553
|
-
ownerClause = `
|
|
621
|
+
let elevatedLiteral = elevatedGroups.map(g => `'` + g + `'`).join(", ");
|
|
622
|
+
let ownerIdentityPreamble = `
|
|
554
623
|
// ── owner scoping (generated) ──
|
|
555
624
|
// Not read from ctx.args: a predicate deciding what the caller may see must
|
|
556
625
|
// arrive on a channel the caller cannot name, and this field is usually absent
|
|
@@ -561,15 +630,15 @@ function listAllItemsConnection(labelField, filterFieldsOpt, rangeFieldsOpt, sor
|
|
|
561
630
|
const _elevated = [` + elevatedLiteral + `];
|
|
562
631
|
// No identity at all, or an identity with no \`sub\`, is the IAM service caller
|
|
563
632
|
// the API also accepts — inside the trust boundary, and exempt.
|
|
564
|
-
const _exempt = _sub == null || _groups.some(g => _elevated.indexOf(g) >= 0)
|
|
633
|
+
const _exempt = _sub == null || _groups.some(g => _elevated.indexOf(g) >= 0);`;
|
|
634
|
+
let ownerClause = ownerField !== undefined ? (
|
|
635
|
+
ownerIndex$1 !== undefined ? ownerIdentityPreamble : ownerIdentityPreamble + `
|
|
565
636
|
if (!_exempt) {
|
|
566
637
|
names['#owner'] = '` + ownerField + `';
|
|
567
638
|
values[':owner'] = util.dynamodb.toDynamoDB(_sub);
|
|
568
639
|
parts.push('#owner = :owner');
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
ownerClause = "";
|
|
572
|
-
}
|
|
640
|
+
}`
|
|
641
|
+
) : "";
|
|
573
642
|
let retiredClause;
|
|
574
643
|
if (retiredField !== undefined) {
|
|
575
644
|
let elevatedLiteral$1 = elevatedGroups.map(g => `'` + g + `'`).join(", ");
|
|
@@ -621,13 +690,14 @@ function listAllItemsConnection(labelField, filterFieldsOpt, rangeFieldsOpt, sor
|
|
|
621
690
|
parts.push('#` + f + ` <= :` + f + `To');
|
|
622
691
|
}`).join("");
|
|
623
692
|
let sortFieldsLiteral = sortFields.map(f => `'` + f + `'`).join(", ");
|
|
693
|
+
let sortGuard = ownerIndex$1 !== undefined && ownerIndexSortField !== undefined ? "!_indexOrdered && " : "";
|
|
624
694
|
let sortBlock = sortFields.length === 0 ? "" : `
|
|
625
695
|
// Per-page sort (Scan returns items in indeterminate order; ScanIndexForward
|
|
626
696
|
// does not apply to Scan). Global ordering across pages requires v1.5 index
|
|
627
697
|
// promotion; @scanSort is per-page even then.
|
|
628
698
|
const orderBy = ctx.args.orderBy;
|
|
629
699
|
const sortFields = [` + sortFieldsLiteral + `];
|
|
630
|
-
if (orderBy && orderBy.field && sortFields.indexOf(orderBy.field) >= 0) {
|
|
700
|
+
if (` + sortGuard + `orderBy && orderBy.field && sortFields.indexOf(orderBy.field) >= 0) {
|
|
631
701
|
const field = orderBy.field;
|
|
632
702
|
const nulls = items.filter(it => it[field] === null || it[field] === undefined);
|
|
633
703
|
const nonNulls = items.filter(it => it[field] !== null && it[field] !== undefined);
|
|
@@ -642,13 +712,53 @@ function listAllItemsConnection(labelField, filterFieldsOpt, rangeFieldsOpt, sor
|
|
|
642
712
|
if (orderBy.direction === 'DESC') encoded.reverse();
|
|
643
713
|
items = encoded.map(e => JSON.parse(e.split('\\x01')[1])).concat(nulls);
|
|
644
714
|
}`;
|
|
715
|
+
let indexOrderedExpr = ownerIndex$1 !== undefined && ownerIndexSortField !== undefined ? `!_exempt && !!(ctx.args.orderBy && ctx.args.orderBy.field === '` + ownerIndexSortField + `')` : "false";
|
|
716
|
+
let requestOperation = ownerField !== undefined ? (
|
|
717
|
+
ownerIndex$1 !== undefined ? `
|
|
718
|
+
const _indexOrdered = ` + indexOrderedExpr + `;
|
|
719
|
+
const req = _exempt
|
|
720
|
+
? {
|
|
721
|
+
operation: 'Scan',
|
|
722
|
+
limit: ` + listPageWindowBudget + `,
|
|
723
|
+
nextToken: _window,
|
|
724
|
+
}
|
|
725
|
+
: {
|
|
726
|
+
operation: 'Query',
|
|
727
|
+
index: '` + ownerIndex$1 + `',
|
|
728
|
+
query: {
|
|
729
|
+
expression: '#owner = :owner',
|
|
730
|
+
expressionNames: { '#owner': '` + ownerField + `' },
|
|
731
|
+
expressionValues: { ':owner': util.dynamodb.toDynamoDB(_sub) },
|
|
732
|
+
},
|
|
733
|
+
limit: ` + listPageWindowBudget + `,
|
|
734
|
+
nextToken: _window,
|
|
735
|
+
scanIndexForward: !(_indexOrdered && ctx.args.orderBy.direction === 'DESC'),
|
|
736
|
+
};` : `
|
|
737
|
+
const req = {
|
|
738
|
+
operation: 'Scan',
|
|
739
|
+
limit: ` + listPageWindowBudget + `,
|
|
740
|
+
nextToken: _window,
|
|
741
|
+
};`
|
|
742
|
+
) : `
|
|
743
|
+
const req = {
|
|
744
|
+
operation: 'Scan',
|
|
745
|
+
limit: ` + listPageWindowBudget + `,
|
|
746
|
+
nextToken: _window,
|
|
747
|
+
};`;
|
|
748
|
+
let requestPathGuard = Stdlib_Option.isSome(ownerIndex$1) ? cursorPathGuard : "";
|
|
749
|
+
let responsePathPreamble = ownerIndex$1 !== undefined ? ownerIdentityPreamble + `
|
|
750
|
+
const _path = _exempt ? 's' : 'q';
|
|
751
|
+
const _indexOrdered = ` + indexOrderedExpr + `;` : "";
|
|
752
|
+
let pageResponse = ownerIndex$1 !== undefined ? connectionPageResponse("_path", true) : connectionPageResponse(undefined, true);
|
|
645
753
|
return importUtil + `
|
|
646
754
|
export function request(ctx) {
|
|
647
|
-
//
|
|
648
|
-
//
|
|
649
|
-
//
|
|
650
|
-
|
|
651
|
-
|
|
755
|
+
// 'before' IS served — the page is cut backward out of the window the cursor
|
|
756
|
+
// names. 'last' is not: "the last N rows of the list" needs the end of the
|
|
757
|
+
// list, which a forward-only Scan cursor cannot reach. The ordered
|
|
758
|
+
// {single}Items connection (queryItemsWithSortConditions) has a real keyset
|
|
759
|
+
// cursor and honours both — direct callers who need 'last' there.
|
|
760
|
+
if (ctx.args.last != null) {
|
|
761
|
+
util.error('last is not supported on full-list connections; page backward with first and before.', 'UnsupportedPagination');
|
|
652
762
|
}
|
|
653
763
|
const filter = ctx.args.filter ?? {};
|
|
654
764
|
const names = {};
|
|
@@ -673,18 +783,14 @@ export function request(ctx) {
|
|
|
673
783
|
});
|
|
674
784
|
parts.push('#id IN (' + placeholders.join(', ') + ')');
|
|
675
785
|
}` + filterClauses + rangeClauses + requireAttributeClause + ownerClause + retiredClause + `
|
|
676
|
-
|
|
677
|
-
//
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
operation: 'Scan',
|
|
685
|
-
limit: (ctx.args.first ?? 50),
|
|
686
|
-
nextToken: after,
|
|
687
|
-
};
|
|
786
|
+
` + listCursorPreamble + requestPathGuard + `
|
|
787
|
+
// The one page a cursor cannot reach: it begins in an earlier window, and a
|
|
788
|
+
// continuation token cannot name the one before it. Refused by itself rather
|
|
789
|
+
// than folded into the 'last' guard, because the two are different limits and a
|
|
790
|
+
// caller can act on this one (page forward from the start).
|
|
791
|
+
if (_backward && _upTo <= 0 && _window !== null) {
|
|
792
|
+
util.error('The previous page begins in an earlier read window, which this cursor cannot name; page forward from the start.', 'UnsupportedPagination');
|
|
793
|
+
}` + requestOperation + `
|
|
688
794
|
if (parts.length > 0) {
|
|
689
795
|
req.filter = {
|
|
690
796
|
expression: parts.join(' AND '),
|
|
@@ -696,30 +802,7 @@ export function request(ctx) {
|
|
|
696
802
|
}
|
|
697
803
|
export function response(ctx) {
|
|
698
804
|
if (ctx.error) util.error(ctx.error.message, ctx.error.type);
|
|
699
|
-
let items = ctx.result?.items ?? [];` + sortBlock + `
|
|
700
|
-
// One Scan continuation token per page; encode it (with the item's page index for a
|
|
701
|
-
// unique, opaque Relay cursor). The request side decodes .token back to the raw
|
|
702
|
-
// DynamoDB nextToken (Fix 1).
|
|
703
|
-
const next = ctx.result?.nextToken ?? null;
|
|
704
|
-
const edges = items.map((item, i) => ({
|
|
705
|
-
node: item,
|
|
706
|
-
cursor: util.base64Encode(JSON.stringify({ token: next, index: i })),
|
|
707
|
-
}));
|
|
708
|
-
// A filtered/1MB-capped page can be empty or short while next is still set (limit
|
|
709
|
-
// caps rows scanned, not returned). The token is page-level, so synthesise a
|
|
710
|
-
// boundary cursor from it alone so a client can resume past a fully-filtered-out
|
|
711
|
-
// page instead of restarting from page 1 (Fix 3). The request only reads .token,
|
|
712
|
-
// so index -1 is inert on resume.
|
|
713
|
-
const boundary = next ? util.base64Encode(JSON.stringify({ token: next, index: -1 })) : null;
|
|
714
|
-
return {
|
|
715
|
-
edges,
|
|
716
|
-
pageInfo: {
|
|
717
|
-
hasNextPage: !!next,
|
|
718
|
-
hasPreviousPage: !!ctx.args.after,
|
|
719
|
-
startCursor: edges.length > 0 ? edges[0].cursor : boundary,
|
|
720
|
-
endCursor: edges.length > 0 ? edges[edges.length - 1].cursor : boundary,
|
|
721
|
-
},
|
|
722
|
-
};
|
|
805
|
+
let items = ctx.result?.items ?? [];` + responsePathPreamble + sortBlock + listCursorPreamble + pageResponse + `
|
|
723
806
|
}
|
|
724
807
|
`;
|
|
725
808
|
}
|
|
@@ -948,12 +1031,9 @@ export function request(ctx) {
|
|
|
948
1031
|
}
|
|
949
1032
|
export function response(ctx) {
|
|
950
1033
|
if (ctx.error) util.error(ctx.error.message, ctx.error.type);
|
|
951
|
-
// BatchGetItem returns null
|
|
952
|
-
//
|
|
953
|
-
//
|
|
954
|
-
// missing id makes the entire field fail with "Cannot return null for
|
|
955
|
-
// non-nullable type" and the caller sees data=null. Filter the nulls so
|
|
956
|
-
// the field returns just the items that were found.
|
|
1034
|
+
// BatchGetItem returns null for keys that don't exist, preserving index
|
|
1035
|
+
// correspondence. The SDL declares \`[T!]!\`, so one missing id would null the
|
|
1036
|
+
// whole field — drop them and return what was found.
|
|
957
1037
|
// The owner and retirement guards the list pushes into a FilterExpression,
|
|
958
1038
|
// applied after the read because BatchGetItem has none to push into. A row the
|
|
959
1039
|
// caller does not own is dropped rather than refused, for the reason the
|
|
@@ -1249,6 +1329,12 @@ export {
|
|
|
1249
1329
|
queryByIndex,
|
|
1250
1330
|
queryByIndexDeletable,
|
|
1251
1331
|
queryByIndexSort,
|
|
1332
|
+
pageWindowBudget,
|
|
1333
|
+
listPageWindowBudget,
|
|
1334
|
+
cursorDecode,
|
|
1335
|
+
cursorPathGuard,
|
|
1336
|
+
listCursorPreamble,
|
|
1337
|
+
connectionPageResponse,
|
|
1252
1338
|
indexConnectionResponseCode,
|
|
1253
1339
|
indexBackwardPagingGuard,
|
|
1254
1340
|
indexCursorPreamble,
|
|
@@ -1285,4 +1371,4 @@ export {
|
|
|
1285
1371
|
resolveIdsResult,
|
|
1286
1372
|
$$null,
|
|
1287
1373
|
}
|
|
1288
|
-
/*
|
|
1374
|
+
/* indexConnectionResponseCode Not a pure module */
|