@contello/client 2.1.0 → 2.2.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.
- package/dist/index.cjs +28 -7
- package/dist/index.d.cts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +28 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -612,10 +612,11 @@ function createSelection(source) {
|
|
|
612
612
|
case "entity":
|
|
613
613
|
return `subscription($ids: [ID!]) { source: ${source.subscription}(request: { filter: { ids: $ids } }) ${spread} }`;
|
|
614
614
|
case "route":
|
|
615
|
+
return `subscription($ids: [ID!], $paths: [String!]) { source: ${source.subscription}(request: { ids: $ids, paths: $paths }) ${spread} }`;
|
|
615
616
|
case "asset":
|
|
616
|
-
return `subscription { source: ${source.subscription} ${spread} }`;
|
|
617
|
+
return `subscription($ids: [ID!]) { source: ${source.subscription}(filter: { ids: $ids }) ${spread} }`;
|
|
617
618
|
case "i18nMessage":
|
|
618
|
-
return `subscription($collection: String!) { source: ${source.subscription}(collectionReferenceName: $collection) ${spread} }`;
|
|
619
|
+
return `subscription($collection: String!, $ids: [ID!]) { source: ${source.subscription}(collectionReferenceName: $collection, ids: $ids) ${spread} }`;
|
|
619
620
|
}
|
|
620
621
|
}
|
|
621
622
|
function createSourceSubscription(source) {
|
|
@@ -648,7 +649,7 @@ function createSources(sources, subscribe) {
|
|
|
648
649
|
out[name] = {
|
|
649
650
|
fetch: (vars) => wrap(
|
|
650
651
|
`source:${name}`,
|
|
651
|
-
() =>
|
|
652
|
+
() => collectAsync(
|
|
652
653
|
mapAsync(
|
|
653
654
|
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
654
655
|
(r) => transformResponse(r).source
|
|
@@ -658,11 +659,28 @@ function createSources(sources, subscribe) {
|
|
|
658
659
|
};
|
|
659
660
|
break;
|
|
660
661
|
case "route":
|
|
662
|
+
out[name] = {
|
|
663
|
+
fetch: (vars) => wrap(
|
|
664
|
+
`source:${name}`,
|
|
665
|
+
() => collectAsync(
|
|
666
|
+
mapAsync(
|
|
667
|
+
subscribe(doc, transformVariables({ ids: vars?.ids, paths: vars?.paths })),
|
|
668
|
+
(r) => transformResponse(r).source
|
|
669
|
+
)
|
|
670
|
+
)
|
|
671
|
+
)
|
|
672
|
+
};
|
|
673
|
+
break;
|
|
661
674
|
case "asset":
|
|
662
675
|
out[name] = {
|
|
663
|
-
fetch: () => wrap(
|
|
676
|
+
fetch: (vars) => wrap(
|
|
664
677
|
`source:${name}`,
|
|
665
|
-
() =>
|
|
678
|
+
() => collectAsync(
|
|
679
|
+
mapAsync(
|
|
680
|
+
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
681
|
+
(r) => transformResponse(r).source
|
|
682
|
+
)
|
|
683
|
+
)
|
|
666
684
|
)
|
|
667
685
|
};
|
|
668
686
|
break;
|
|
@@ -670,9 +688,12 @@ function createSources(sources, subscribe) {
|
|
|
670
688
|
out[name] = {
|
|
671
689
|
fetch: (vars) => wrap(
|
|
672
690
|
`source:${name}`,
|
|
673
|
-
() =>
|
|
691
|
+
() => collectAsync(
|
|
674
692
|
mapAsync(
|
|
675
|
-
subscribe(
|
|
693
|
+
subscribe(
|
|
694
|
+
doc,
|
|
695
|
+
transformVariables({ collection: vars.collection, ids: vars.ids })
|
|
696
|
+
),
|
|
676
697
|
(r) => transformResponse(r).source
|
|
677
698
|
)
|
|
678
699
|
)
|
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
|
@@ -566,10 +566,11 @@ function createSelection(source) {
|
|
|
566
566
|
case "entity":
|
|
567
567
|
return `subscription($ids: [ID!]) { source: ${source.subscription}(request: { filter: { ids: $ids } }) ${spread} }`;
|
|
568
568
|
case "route":
|
|
569
|
+
return `subscription($ids: [ID!], $paths: [String!]) { source: ${source.subscription}(request: { ids: $ids, paths: $paths }) ${spread} }`;
|
|
569
570
|
case "asset":
|
|
570
|
-
return `subscription { source: ${source.subscription} ${spread} }`;
|
|
571
|
+
return `subscription($ids: [ID!]) { source: ${source.subscription}(filter: { ids: $ids }) ${spread} }`;
|
|
571
572
|
case "i18nMessage":
|
|
572
|
-
return `subscription($collection: String!) { source: ${source.subscription}(collectionReferenceName: $collection) ${spread} }`;
|
|
573
|
+
return `subscription($collection: String!, $ids: [ID!]) { source: ${source.subscription}(collectionReferenceName: $collection, ids: $ids) ${spread} }`;
|
|
573
574
|
}
|
|
574
575
|
}
|
|
575
576
|
function createSourceSubscription(source) {
|
|
@@ -602,7 +603,7 @@ function createSources(sources, subscribe) {
|
|
|
602
603
|
out[name] = {
|
|
603
604
|
fetch: (vars) => wrap(
|
|
604
605
|
`source:${name}`,
|
|
605
|
-
() =>
|
|
606
|
+
() => collectAsync(
|
|
606
607
|
mapAsync(
|
|
607
608
|
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
608
609
|
(r) => transformResponse(r).source
|
|
@@ -612,11 +613,28 @@ function createSources(sources, subscribe) {
|
|
|
612
613
|
};
|
|
613
614
|
break;
|
|
614
615
|
case "route":
|
|
616
|
+
out[name] = {
|
|
617
|
+
fetch: (vars) => wrap(
|
|
618
|
+
`source:${name}`,
|
|
619
|
+
() => collectAsync(
|
|
620
|
+
mapAsync(
|
|
621
|
+
subscribe(doc, transformVariables({ ids: vars?.ids, paths: vars?.paths })),
|
|
622
|
+
(r) => transformResponse(r).source
|
|
623
|
+
)
|
|
624
|
+
)
|
|
625
|
+
)
|
|
626
|
+
};
|
|
627
|
+
break;
|
|
615
628
|
case "asset":
|
|
616
629
|
out[name] = {
|
|
617
|
-
fetch: () => wrap(
|
|
630
|
+
fetch: (vars) => wrap(
|
|
618
631
|
`source:${name}`,
|
|
619
|
-
() =>
|
|
632
|
+
() => collectAsync(
|
|
633
|
+
mapAsync(
|
|
634
|
+
subscribe(doc, transformVariables({ ids: vars?.ids })),
|
|
635
|
+
(r) => transformResponse(r).source
|
|
636
|
+
)
|
|
637
|
+
)
|
|
620
638
|
)
|
|
621
639
|
};
|
|
622
640
|
break;
|
|
@@ -624,9 +642,12 @@ function createSources(sources, subscribe) {
|
|
|
624
642
|
out[name] = {
|
|
625
643
|
fetch: (vars) => wrap(
|
|
626
644
|
`source:${name}`,
|
|
627
|
-
() =>
|
|
645
|
+
() => collectAsync(
|
|
628
646
|
mapAsync(
|
|
629
|
-
subscribe(
|
|
647
|
+
subscribe(
|
|
648
|
+
doc,
|
|
649
|
+
transformVariables({ collection: vars.collection, ids: vars.ids })
|
|
650
|
+
),
|
|
630
651
|
(r) => transformResponse(r).source
|
|
631
652
|
)
|
|
632
653
|
)
|