@contello/client 2.1.1 → 2.2.1
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/dist/index.cjs +139 -124
- package/dist/index.d.cts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +139 -124
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -444,6 +444,144 @@ function encodeLocalDate(value) {
|
|
|
444
444
|
return `${pad4(value.year)}-${pad2(value.month)}-${pad2(value.day)}T00:00:00Z`;
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
+
// src/transform-variables.ts
|
|
448
|
+
function transformVariables(value) {
|
|
449
|
+
if (value === null || value === void 0) {
|
|
450
|
+
return value;
|
|
451
|
+
}
|
|
452
|
+
if (Array.isArray(value)) {
|
|
453
|
+
return value.map((item) => transformVariables(item));
|
|
454
|
+
}
|
|
455
|
+
if (typeof value !== "object") {
|
|
456
|
+
return value;
|
|
457
|
+
}
|
|
458
|
+
if (isLocalDateTime(value)) {
|
|
459
|
+
return encodeLocalDateTime(value);
|
|
460
|
+
}
|
|
461
|
+
if (isLocalDate(value)) {
|
|
462
|
+
return encodeLocalDate(value);
|
|
463
|
+
}
|
|
464
|
+
const obj = value;
|
|
465
|
+
const out = {};
|
|
466
|
+
for (const key of Object.keys(obj)) {
|
|
467
|
+
out[key] = transformVariables(obj[key]);
|
|
468
|
+
}
|
|
469
|
+
return out;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// src/rpc.ts
|
|
473
|
+
function buildRpc(operations, subscribe) {
|
|
474
|
+
const rpc = {};
|
|
475
|
+
for (const [name, def] of Object.entries(operations)) {
|
|
476
|
+
if (def.kind === "subscription") {
|
|
477
|
+
rpc[name] = (variables) => subscribe(def.document, transformVariables(variables));
|
|
478
|
+
} else {
|
|
479
|
+
rpc[name] = (variables) => wrap(`rpc:${name}`, () => firstAsync(subscribe(def.document, transformVariables(variables))));
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return rpc;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// src/source-subscription.ts
|
|
486
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
487
|
+
function createSelection(source) {
|
|
488
|
+
const spread = `{ ...${source.fragment} }`;
|
|
489
|
+
switch (source.__cardinality) {
|
|
490
|
+
case "singleton":
|
|
491
|
+
return `subscription { source: ${source.subscription} ${spread} }`;
|
|
492
|
+
case "entity":
|
|
493
|
+
return `subscription($ids: [ID!]) { source: ${source.subscription}(request: { filter: { ids: $ids } }) ${spread} }`;
|
|
494
|
+
case "route":
|
|
495
|
+
return `subscription($ids: [ID!], $paths: [String!]) { source: ${source.subscription}(request: { ids: $ids, paths: $paths }) ${spread} }`;
|
|
496
|
+
case "asset":
|
|
497
|
+
return `subscription($ids: [ID!]) { source: ${source.subscription}(filter: { ids: $ids }) ${spread} }`;
|
|
498
|
+
case "i18nMessage":
|
|
499
|
+
return `subscription($collection: String!, $ids: [ID!]) { source: ${source.subscription}(collectionReferenceName: $collection, ids: $ids) ${spread} }`;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function createSourceSubscription(source) {
|
|
503
|
+
const cached = cache.get(source);
|
|
504
|
+
if (cached !== void 0) {
|
|
505
|
+
return cached;
|
|
506
|
+
}
|
|
507
|
+
const doc = `${source.document}
|
|
508
|
+
${createSelection(source)}`;
|
|
509
|
+
cache.set(source, doc);
|
|
510
|
+
return doc;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/sources.ts
|
|
514
|
+
function createSources(sources, subscribe) {
|
|
515
|
+
const out = {};
|
|
516
|
+
for (const [name, source] of Object.entries(sources)) {
|
|
517
|
+
const def = source;
|
|
518
|
+
const doc = createSourceSubscription(def);
|
|
519
|
+
switch (def.__cardinality) {
|
|
520
|
+
case "singleton":
|
|
521
|
+
out[name] = {
|
|
522
|
+
fetch: () => wrap(`source:${name}`, () => firstAsync(mapAsync(subscribe(doc), (r) => r.source)))
|
|
523
|
+
};
|
|
524
|
+
break;
|
|
525
|
+
case "entity":
|
|
526
|
+
out[name] = {
|
|
527
|
+
fetch: (vars) => wrap(
|
|
528
|
+
`source:${name}`,
|
|
529
|
+
() => collectAsync(
|
|
530
|
+
mapAsync(
|
|
531
|
+
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
532
|
+
(r) => r.source
|
|
533
|
+
)
|
|
534
|
+
)
|
|
535
|
+
)
|
|
536
|
+
};
|
|
537
|
+
break;
|
|
538
|
+
case "route":
|
|
539
|
+
out[name] = {
|
|
540
|
+
fetch: (vars) => wrap(
|
|
541
|
+
`source:${name}`,
|
|
542
|
+
() => collectAsync(
|
|
543
|
+
mapAsync(
|
|
544
|
+
subscribe(doc, transformVariables({ ids: vars?.ids, paths: vars?.paths })),
|
|
545
|
+
(r) => r.source
|
|
546
|
+
)
|
|
547
|
+
)
|
|
548
|
+
)
|
|
549
|
+
};
|
|
550
|
+
break;
|
|
551
|
+
case "asset":
|
|
552
|
+
out[name] = {
|
|
553
|
+
fetch: (vars) => wrap(
|
|
554
|
+
`source:${name}`,
|
|
555
|
+
() => collectAsync(
|
|
556
|
+
mapAsync(
|
|
557
|
+
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
558
|
+
(r) => r.source
|
|
559
|
+
)
|
|
560
|
+
)
|
|
561
|
+
)
|
|
562
|
+
};
|
|
563
|
+
break;
|
|
564
|
+
case "i18nMessage":
|
|
565
|
+
out[name] = {
|
|
566
|
+
fetch: (vars) => wrap(
|
|
567
|
+
`source:${name}`,
|
|
568
|
+
() => collectAsync(
|
|
569
|
+
mapAsync(
|
|
570
|
+
subscribe(
|
|
571
|
+
doc,
|
|
572
|
+
transformVariables({ collection: vars.collection, ids: vars.ids })
|
|
573
|
+
),
|
|
574
|
+
(r) => r.source
|
|
575
|
+
)
|
|
576
|
+
)
|
|
577
|
+
)
|
|
578
|
+
};
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return out;
|
|
583
|
+
}
|
|
584
|
+
|
|
447
585
|
// src/transform-response.ts
|
|
448
586
|
var FLAT_PREFIX = "_flat_";
|
|
449
587
|
var LDT_PREFIX = "_ldt_";
|
|
@@ -561,129 +699,6 @@ function resolveNestedRefs(value, flatMap) {
|
|
|
561
699
|
}
|
|
562
700
|
}
|
|
563
701
|
|
|
564
|
-
// src/transform-variables.ts
|
|
565
|
-
function transformVariables(value) {
|
|
566
|
-
if (value === null || value === void 0) {
|
|
567
|
-
return value;
|
|
568
|
-
}
|
|
569
|
-
if (Array.isArray(value)) {
|
|
570
|
-
return value.map((item) => transformVariables(item));
|
|
571
|
-
}
|
|
572
|
-
if (typeof value !== "object") {
|
|
573
|
-
return value;
|
|
574
|
-
}
|
|
575
|
-
if (isLocalDateTime(value)) {
|
|
576
|
-
return encodeLocalDateTime(value);
|
|
577
|
-
}
|
|
578
|
-
if (isLocalDate(value)) {
|
|
579
|
-
return encodeLocalDate(value);
|
|
580
|
-
}
|
|
581
|
-
const obj = value;
|
|
582
|
-
const out = {};
|
|
583
|
-
for (const key of Object.keys(obj)) {
|
|
584
|
-
out[key] = transformVariables(obj[key]);
|
|
585
|
-
}
|
|
586
|
-
return out;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// src/rpc.ts
|
|
590
|
-
function buildRpc(operations, subscribe) {
|
|
591
|
-
const rpc = {};
|
|
592
|
-
for (const [name, def] of Object.entries(operations)) {
|
|
593
|
-
if (def.kind === "subscription") {
|
|
594
|
-
rpc[name] = (variables) => mapAsync(subscribe(def.document, transformVariables(variables)), transformResponse);
|
|
595
|
-
} else {
|
|
596
|
-
rpc[name] = (variables) => wrap(
|
|
597
|
-
`rpc:${name}`,
|
|
598
|
-
() => firstAsync(mapAsync(subscribe(def.document, transformVariables(variables)), transformResponse))
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return rpc;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// src/source-subscription.ts
|
|
606
|
-
var cache = /* @__PURE__ */ new WeakMap();
|
|
607
|
-
function createSelection(source) {
|
|
608
|
-
const spread = `{ ...${source.fragment} }`;
|
|
609
|
-
switch (source.__cardinality) {
|
|
610
|
-
case "singleton":
|
|
611
|
-
return `subscription { source: ${source.subscription} ${spread} }`;
|
|
612
|
-
case "entity":
|
|
613
|
-
return `subscription($ids: [ID!]) { source: ${source.subscription}(request: { filter: { ids: $ids } }) ${spread} }`;
|
|
614
|
-
case "route":
|
|
615
|
-
case "asset":
|
|
616
|
-
return `subscription { source: ${source.subscription} ${spread} }`;
|
|
617
|
-
case "i18nMessage":
|
|
618
|
-
return `subscription($collection: String!) { source: ${source.subscription}(collectionReferenceName: $collection) ${spread} }`;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
function createSourceSubscription(source) {
|
|
622
|
-
const cached = cache.get(source);
|
|
623
|
-
if (cached !== void 0) {
|
|
624
|
-
return cached;
|
|
625
|
-
}
|
|
626
|
-
const doc = `${source.document}
|
|
627
|
-
${createSelection(source)}`;
|
|
628
|
-
cache.set(source, doc);
|
|
629
|
-
return doc;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// src/sources.ts
|
|
633
|
-
function createSources(sources, subscribe) {
|
|
634
|
-
const out = {};
|
|
635
|
-
for (const [name, source] of Object.entries(sources)) {
|
|
636
|
-
const def = source;
|
|
637
|
-
const doc = createSourceSubscription(def);
|
|
638
|
-
switch (def.__cardinality) {
|
|
639
|
-
case "singleton":
|
|
640
|
-
out[name] = {
|
|
641
|
-
fetch: () => wrap(
|
|
642
|
-
`source:${name}`,
|
|
643
|
-
() => firstAsync(mapAsync(subscribe(doc), (r) => transformResponse(r).source))
|
|
644
|
-
)
|
|
645
|
-
};
|
|
646
|
-
break;
|
|
647
|
-
case "entity":
|
|
648
|
-
out[name] = {
|
|
649
|
-
fetch: (vars) => wrap(
|
|
650
|
-
`source:${name}`,
|
|
651
|
-
() => collectAsync(
|
|
652
|
-
mapAsync(
|
|
653
|
-
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
654
|
-
(r) => transformResponse(r).source
|
|
655
|
-
)
|
|
656
|
-
)
|
|
657
|
-
)
|
|
658
|
-
};
|
|
659
|
-
break;
|
|
660
|
-
case "route":
|
|
661
|
-
case "asset":
|
|
662
|
-
out[name] = {
|
|
663
|
-
fetch: () => wrap(
|
|
664
|
-
`source:${name}`,
|
|
665
|
-
() => collectAsync(mapAsync(subscribe(doc), (r) => transformResponse(r).source))
|
|
666
|
-
)
|
|
667
|
-
};
|
|
668
|
-
break;
|
|
669
|
-
case "i18nMessage":
|
|
670
|
-
out[name] = {
|
|
671
|
-
fetch: (vars) => wrap(
|
|
672
|
-
`source:${name}`,
|
|
673
|
-
() => collectAsync(
|
|
674
|
-
mapAsync(
|
|
675
|
-
subscribe(doc, { collection: vars.collection }),
|
|
676
|
-
(r) => transformResponse(r).source
|
|
677
|
-
)
|
|
678
|
-
)
|
|
679
|
-
)
|
|
680
|
-
};
|
|
681
|
-
break;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
return out;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
702
|
// src/upload.ts
|
|
688
703
|
var DEFAULT_CHUNK_SIZE = 4 * 1024 * 1024;
|
|
689
704
|
function isUint8Array(data) {
|
|
@@ -891,7 +906,7 @@ var ContelloClient = class {
|
|
|
891
906
|
{ query, variables },
|
|
892
907
|
{
|
|
893
908
|
next(msg) {
|
|
894
|
-
const value = msg.data;
|
|
909
|
+
const value = transformResponse(msg.data);
|
|
895
910
|
if (value === void 0 || value === null) {
|
|
896
911
|
return;
|
|
897
912
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -38,9 +38,9 @@ type Rpc<T extends OperationMap> = {
|
|
|
38
38
|
* Discriminator for how a SourceDef binds to a Subscription field:
|
|
39
39
|
* - `entity` — a Contello entity model collection (`categoriesBatch` etc.), accepts optional `{ ids }` filter
|
|
40
40
|
* - `singleton` — a single Contello entity (`config` etc.), no args
|
|
41
|
-
* - `route` — built-in: `contelloRoutesBatch`,
|
|
42
|
-
* - `asset` — built-in: `contelloAssetsBatch`,
|
|
43
|
-
* - `i18nMessage` — built-in: `contelloI18nMessagesBatch`, requires `{ collection }`
|
|
41
|
+
* - `route` — built-in: `contelloRoutesBatch`, optional `{ ids, paths }` filter
|
|
42
|
+
* - `asset` — built-in: `contelloAssetsBatch`, optional `{ ids }` filter
|
|
43
|
+
* - `i18nMessage` — built-in: `contelloI18nMessagesBatch`, requires `{ collection }` and optional `{ ids }` filter
|
|
44
44
|
*/
|
|
45
45
|
type SourceCardinality = 'entity' | 'singleton' | 'route' | 'asset' | 'i18nMessage';
|
|
46
46
|
type SourceDef<TModel extends string = string, TCardinality extends SourceCardinality = SourceCardinality, TResult = unknown> = {
|
|
@@ -69,8 +69,14 @@ type Schema<TOps extends OperationMap = OperationMap, TSources extends SourceMap
|
|
|
69
69
|
};
|
|
70
70
|
type SourceFetcherFor<S> = S extends SourceDef<string, 'singleton', infer R> ? () => Promise<R> : S extends SourceDef<string, 'entity', infer R> ? (vars?: {
|
|
71
71
|
ids?: string[];
|
|
72
|
-
}) => Promise<R[]> : S extends SourceDef<string, 'route', infer R> ? (
|
|
72
|
+
}) => Promise<R[]> : S extends SourceDef<string, 'route', infer R> ? (vars?: {
|
|
73
|
+
ids?: string[] | undefined;
|
|
74
|
+
paths?: string[] | undefined;
|
|
75
|
+
} | undefined) => Promise<R[]> : S extends SourceDef<string, 'asset', infer R> ? (vars?: {
|
|
76
|
+
ids?: string[] | undefined;
|
|
77
|
+
} | undefined) => Promise<R[]> : S extends SourceDef<string, 'i18nMessage', infer R> ? (vars: {
|
|
73
78
|
collection: string;
|
|
79
|
+
ids?: string[] | undefined;
|
|
74
80
|
}) => Promise<R[]> : never;
|
|
75
81
|
/** Per-source runtime accessor: `client.sources.category.fetch()` → `Promise<CategoryFragment[]>` etc. */
|
|
76
82
|
type SourceAccessors<TSources extends SourceMap> = {
|
package/dist/index.d.ts
CHANGED
|
@@ -38,9 +38,9 @@ type Rpc<T extends OperationMap> = {
|
|
|
38
38
|
* Discriminator for how a SourceDef binds to a Subscription field:
|
|
39
39
|
* - `entity` — a Contello entity model collection (`categoriesBatch` etc.), accepts optional `{ ids }` filter
|
|
40
40
|
* - `singleton` — a single Contello entity (`config` etc.), no args
|
|
41
|
-
* - `route` — built-in: `contelloRoutesBatch`,
|
|
42
|
-
* - `asset` — built-in: `contelloAssetsBatch`,
|
|
43
|
-
* - `i18nMessage` — built-in: `contelloI18nMessagesBatch`, requires `{ collection }`
|
|
41
|
+
* - `route` — built-in: `contelloRoutesBatch`, optional `{ ids, paths }` filter
|
|
42
|
+
* - `asset` — built-in: `contelloAssetsBatch`, optional `{ ids }` filter
|
|
43
|
+
* - `i18nMessage` — built-in: `contelloI18nMessagesBatch`, requires `{ collection }` and optional `{ ids }` filter
|
|
44
44
|
*/
|
|
45
45
|
type SourceCardinality = 'entity' | 'singleton' | 'route' | 'asset' | 'i18nMessage';
|
|
46
46
|
type SourceDef<TModel extends string = string, TCardinality extends SourceCardinality = SourceCardinality, TResult = unknown> = {
|
|
@@ -69,8 +69,14 @@ type Schema<TOps extends OperationMap = OperationMap, TSources extends SourceMap
|
|
|
69
69
|
};
|
|
70
70
|
type SourceFetcherFor<S> = S extends SourceDef<string, 'singleton', infer R> ? () => Promise<R> : S extends SourceDef<string, 'entity', infer R> ? (vars?: {
|
|
71
71
|
ids?: string[];
|
|
72
|
-
}) => Promise<R[]> : S extends SourceDef<string, 'route', infer R> ? (
|
|
72
|
+
}) => Promise<R[]> : S extends SourceDef<string, 'route', infer R> ? (vars?: {
|
|
73
|
+
ids?: string[] | undefined;
|
|
74
|
+
paths?: string[] | undefined;
|
|
75
|
+
} | undefined) => Promise<R[]> : S extends SourceDef<string, 'asset', infer R> ? (vars?: {
|
|
76
|
+
ids?: string[] | undefined;
|
|
77
|
+
} | undefined) => Promise<R[]> : S extends SourceDef<string, 'i18nMessage', infer R> ? (vars: {
|
|
73
78
|
collection: string;
|
|
79
|
+
ids?: string[] | undefined;
|
|
74
80
|
}) => Promise<R[]> : never;
|
|
75
81
|
/** Per-source runtime accessor: `client.sources.category.fetch()` → `Promise<CategoryFragment[]>` etc. */
|
|
76
82
|
type SourceAccessors<TSources extends SourceMap> = {
|
package/dist/index.js
CHANGED
|
@@ -398,6 +398,144 @@ function encodeLocalDate(value) {
|
|
|
398
398
|
return `${pad4(value.year)}-${pad2(value.month)}-${pad2(value.day)}T00:00:00Z`;
|
|
399
399
|
}
|
|
400
400
|
|
|
401
|
+
// src/transform-variables.ts
|
|
402
|
+
function transformVariables(value) {
|
|
403
|
+
if (value === null || value === void 0) {
|
|
404
|
+
return value;
|
|
405
|
+
}
|
|
406
|
+
if (Array.isArray(value)) {
|
|
407
|
+
return value.map((item) => transformVariables(item));
|
|
408
|
+
}
|
|
409
|
+
if (typeof value !== "object") {
|
|
410
|
+
return value;
|
|
411
|
+
}
|
|
412
|
+
if (isLocalDateTime(value)) {
|
|
413
|
+
return encodeLocalDateTime(value);
|
|
414
|
+
}
|
|
415
|
+
if (isLocalDate(value)) {
|
|
416
|
+
return encodeLocalDate(value);
|
|
417
|
+
}
|
|
418
|
+
const obj = value;
|
|
419
|
+
const out = {};
|
|
420
|
+
for (const key of Object.keys(obj)) {
|
|
421
|
+
out[key] = transformVariables(obj[key]);
|
|
422
|
+
}
|
|
423
|
+
return out;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// src/rpc.ts
|
|
427
|
+
function buildRpc(operations, subscribe) {
|
|
428
|
+
const rpc = {};
|
|
429
|
+
for (const [name, def] of Object.entries(operations)) {
|
|
430
|
+
if (def.kind === "subscription") {
|
|
431
|
+
rpc[name] = (variables) => subscribe(def.document, transformVariables(variables));
|
|
432
|
+
} else {
|
|
433
|
+
rpc[name] = (variables) => wrap(`rpc:${name}`, () => firstAsync(subscribe(def.document, transformVariables(variables))));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return rpc;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/source-subscription.ts
|
|
440
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
441
|
+
function createSelection(source) {
|
|
442
|
+
const spread = `{ ...${source.fragment} }`;
|
|
443
|
+
switch (source.__cardinality) {
|
|
444
|
+
case "singleton":
|
|
445
|
+
return `subscription { source: ${source.subscription} ${spread} }`;
|
|
446
|
+
case "entity":
|
|
447
|
+
return `subscription($ids: [ID!]) { source: ${source.subscription}(request: { filter: { ids: $ids } }) ${spread} }`;
|
|
448
|
+
case "route":
|
|
449
|
+
return `subscription($ids: [ID!], $paths: [String!]) { source: ${source.subscription}(request: { ids: $ids, paths: $paths }) ${spread} }`;
|
|
450
|
+
case "asset":
|
|
451
|
+
return `subscription($ids: [ID!]) { source: ${source.subscription}(filter: { ids: $ids }) ${spread} }`;
|
|
452
|
+
case "i18nMessage":
|
|
453
|
+
return `subscription($collection: String!, $ids: [ID!]) { source: ${source.subscription}(collectionReferenceName: $collection, ids: $ids) ${spread} }`;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function createSourceSubscription(source) {
|
|
457
|
+
const cached = cache.get(source);
|
|
458
|
+
if (cached !== void 0) {
|
|
459
|
+
return cached;
|
|
460
|
+
}
|
|
461
|
+
const doc = `${source.document}
|
|
462
|
+
${createSelection(source)}`;
|
|
463
|
+
cache.set(source, doc);
|
|
464
|
+
return doc;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/sources.ts
|
|
468
|
+
function createSources(sources, subscribe) {
|
|
469
|
+
const out = {};
|
|
470
|
+
for (const [name, source] of Object.entries(sources)) {
|
|
471
|
+
const def = source;
|
|
472
|
+
const doc = createSourceSubscription(def);
|
|
473
|
+
switch (def.__cardinality) {
|
|
474
|
+
case "singleton":
|
|
475
|
+
out[name] = {
|
|
476
|
+
fetch: () => wrap(`source:${name}`, () => firstAsync(mapAsync(subscribe(doc), (r) => r.source)))
|
|
477
|
+
};
|
|
478
|
+
break;
|
|
479
|
+
case "entity":
|
|
480
|
+
out[name] = {
|
|
481
|
+
fetch: (vars) => wrap(
|
|
482
|
+
`source:${name}`,
|
|
483
|
+
() => collectAsync(
|
|
484
|
+
mapAsync(
|
|
485
|
+
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
486
|
+
(r) => r.source
|
|
487
|
+
)
|
|
488
|
+
)
|
|
489
|
+
)
|
|
490
|
+
};
|
|
491
|
+
break;
|
|
492
|
+
case "route":
|
|
493
|
+
out[name] = {
|
|
494
|
+
fetch: (vars) => wrap(
|
|
495
|
+
`source:${name}`,
|
|
496
|
+
() => collectAsync(
|
|
497
|
+
mapAsync(
|
|
498
|
+
subscribe(doc, transformVariables({ ids: vars?.ids, paths: vars?.paths })),
|
|
499
|
+
(r) => r.source
|
|
500
|
+
)
|
|
501
|
+
)
|
|
502
|
+
)
|
|
503
|
+
};
|
|
504
|
+
break;
|
|
505
|
+
case "asset":
|
|
506
|
+
out[name] = {
|
|
507
|
+
fetch: (vars) => wrap(
|
|
508
|
+
`source:${name}`,
|
|
509
|
+
() => collectAsync(
|
|
510
|
+
mapAsync(
|
|
511
|
+
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
512
|
+
(r) => r.source
|
|
513
|
+
)
|
|
514
|
+
)
|
|
515
|
+
)
|
|
516
|
+
};
|
|
517
|
+
break;
|
|
518
|
+
case "i18nMessage":
|
|
519
|
+
out[name] = {
|
|
520
|
+
fetch: (vars) => wrap(
|
|
521
|
+
`source:${name}`,
|
|
522
|
+
() => collectAsync(
|
|
523
|
+
mapAsync(
|
|
524
|
+
subscribe(
|
|
525
|
+
doc,
|
|
526
|
+
transformVariables({ collection: vars.collection, ids: vars.ids })
|
|
527
|
+
),
|
|
528
|
+
(r) => r.source
|
|
529
|
+
)
|
|
530
|
+
)
|
|
531
|
+
)
|
|
532
|
+
};
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return out;
|
|
537
|
+
}
|
|
538
|
+
|
|
401
539
|
// src/transform-response.ts
|
|
402
540
|
var FLAT_PREFIX = "_flat_";
|
|
403
541
|
var LDT_PREFIX = "_ldt_";
|
|
@@ -515,129 +653,6 @@ function resolveNestedRefs(value, flatMap) {
|
|
|
515
653
|
}
|
|
516
654
|
}
|
|
517
655
|
|
|
518
|
-
// src/transform-variables.ts
|
|
519
|
-
function transformVariables(value) {
|
|
520
|
-
if (value === null || value === void 0) {
|
|
521
|
-
return value;
|
|
522
|
-
}
|
|
523
|
-
if (Array.isArray(value)) {
|
|
524
|
-
return value.map((item) => transformVariables(item));
|
|
525
|
-
}
|
|
526
|
-
if (typeof value !== "object") {
|
|
527
|
-
return value;
|
|
528
|
-
}
|
|
529
|
-
if (isLocalDateTime(value)) {
|
|
530
|
-
return encodeLocalDateTime(value);
|
|
531
|
-
}
|
|
532
|
-
if (isLocalDate(value)) {
|
|
533
|
-
return encodeLocalDate(value);
|
|
534
|
-
}
|
|
535
|
-
const obj = value;
|
|
536
|
-
const out = {};
|
|
537
|
-
for (const key of Object.keys(obj)) {
|
|
538
|
-
out[key] = transformVariables(obj[key]);
|
|
539
|
-
}
|
|
540
|
-
return out;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// src/rpc.ts
|
|
544
|
-
function buildRpc(operations, subscribe) {
|
|
545
|
-
const rpc = {};
|
|
546
|
-
for (const [name, def] of Object.entries(operations)) {
|
|
547
|
-
if (def.kind === "subscription") {
|
|
548
|
-
rpc[name] = (variables) => mapAsync(subscribe(def.document, transformVariables(variables)), transformResponse);
|
|
549
|
-
} else {
|
|
550
|
-
rpc[name] = (variables) => wrap(
|
|
551
|
-
`rpc:${name}`,
|
|
552
|
-
() => firstAsync(mapAsync(subscribe(def.document, transformVariables(variables)), transformResponse))
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return rpc;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
// src/source-subscription.ts
|
|
560
|
-
var cache = /* @__PURE__ */ new WeakMap();
|
|
561
|
-
function createSelection(source) {
|
|
562
|
-
const spread = `{ ...${source.fragment} }`;
|
|
563
|
-
switch (source.__cardinality) {
|
|
564
|
-
case "singleton":
|
|
565
|
-
return `subscription { source: ${source.subscription} ${spread} }`;
|
|
566
|
-
case "entity":
|
|
567
|
-
return `subscription($ids: [ID!]) { source: ${source.subscription}(request: { filter: { ids: $ids } }) ${spread} }`;
|
|
568
|
-
case "route":
|
|
569
|
-
case "asset":
|
|
570
|
-
return `subscription { source: ${source.subscription} ${spread} }`;
|
|
571
|
-
case "i18nMessage":
|
|
572
|
-
return `subscription($collection: String!) { source: ${source.subscription}(collectionReferenceName: $collection) ${spread} }`;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
function createSourceSubscription(source) {
|
|
576
|
-
const cached = cache.get(source);
|
|
577
|
-
if (cached !== void 0) {
|
|
578
|
-
return cached;
|
|
579
|
-
}
|
|
580
|
-
const doc = `${source.document}
|
|
581
|
-
${createSelection(source)}`;
|
|
582
|
-
cache.set(source, doc);
|
|
583
|
-
return doc;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// src/sources.ts
|
|
587
|
-
function createSources(sources, subscribe) {
|
|
588
|
-
const out = {};
|
|
589
|
-
for (const [name, source] of Object.entries(sources)) {
|
|
590
|
-
const def = source;
|
|
591
|
-
const doc = createSourceSubscription(def);
|
|
592
|
-
switch (def.__cardinality) {
|
|
593
|
-
case "singleton":
|
|
594
|
-
out[name] = {
|
|
595
|
-
fetch: () => wrap(
|
|
596
|
-
`source:${name}`,
|
|
597
|
-
() => firstAsync(mapAsync(subscribe(doc), (r) => transformResponse(r).source))
|
|
598
|
-
)
|
|
599
|
-
};
|
|
600
|
-
break;
|
|
601
|
-
case "entity":
|
|
602
|
-
out[name] = {
|
|
603
|
-
fetch: (vars) => wrap(
|
|
604
|
-
`source:${name}`,
|
|
605
|
-
() => collectAsync(
|
|
606
|
-
mapAsync(
|
|
607
|
-
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
608
|
-
(r) => transformResponse(r).source
|
|
609
|
-
)
|
|
610
|
-
)
|
|
611
|
-
)
|
|
612
|
-
};
|
|
613
|
-
break;
|
|
614
|
-
case "route":
|
|
615
|
-
case "asset":
|
|
616
|
-
out[name] = {
|
|
617
|
-
fetch: () => wrap(
|
|
618
|
-
`source:${name}`,
|
|
619
|
-
() => collectAsync(mapAsync(subscribe(doc), (r) => transformResponse(r).source))
|
|
620
|
-
)
|
|
621
|
-
};
|
|
622
|
-
break;
|
|
623
|
-
case "i18nMessage":
|
|
624
|
-
out[name] = {
|
|
625
|
-
fetch: (vars) => wrap(
|
|
626
|
-
`source:${name}`,
|
|
627
|
-
() => collectAsync(
|
|
628
|
-
mapAsync(
|
|
629
|
-
subscribe(doc, { collection: vars.collection }),
|
|
630
|
-
(r) => transformResponse(r).source
|
|
631
|
-
)
|
|
632
|
-
)
|
|
633
|
-
)
|
|
634
|
-
};
|
|
635
|
-
break;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
return out;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
656
|
// src/upload.ts
|
|
642
657
|
var DEFAULT_CHUNK_SIZE = 4 * 1024 * 1024;
|
|
643
658
|
function isUint8Array(data) {
|
|
@@ -845,7 +860,7 @@ var ContelloClient = class {
|
|
|
845
860
|
{ query, variables },
|
|
846
861
|
{
|
|
847
862
|
next(msg) {
|
|
848
|
-
const value = msg.data;
|
|
863
|
+
const value = transformResponse(msg.data);
|
|
849
864
|
if (value === void 0 || value === null) {
|
|
850
865
|
return;
|
|
851
866
|
}
|