@carddb/client 0.1.1 → 0.1.3
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 +133 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -2
- package/dist/index.d.ts +54 -2
- package/dist/index.js +133 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -747,6 +747,28 @@ var DecksResource = class extends BaseResource {
|
|
|
747
747
|
return result["fetchDeck"] ?? null;
|
|
748
748
|
});
|
|
749
749
|
}
|
|
750
|
+
/**
|
|
751
|
+
* Fetch one deck owned by the current account or API application.
|
|
752
|
+
*/
|
|
753
|
+
async fetchMine(id, options = {}) {
|
|
754
|
+
const key = this.cacheKey("decks", "fetchMine", { id });
|
|
755
|
+
return this.withCache(key, "decks", options, async () => {
|
|
756
|
+
const { query } = core.QueryBuilder.myDeck();
|
|
757
|
+
const result = await this.connection.execute(query, { id });
|
|
758
|
+
return result["myDeck"] ?? null;
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Fetch a hosted deck by canonical or historical slug.
|
|
763
|
+
*/
|
|
764
|
+
async fetchBySlug(publisherSlug, gameKey, slug, options = {}) {
|
|
765
|
+
const key = this.cacheKey("decks", "fetchBySlug", { publisherSlug, gameKey, slug });
|
|
766
|
+
return this.withCache(key, "decks", options, async () => {
|
|
767
|
+
const { query } = core.QueryBuilder.fetchDeckBySlug();
|
|
768
|
+
const result = await this.connection.execute(query, { publisherSlug, gameKey, slug });
|
|
769
|
+
return result["fetchDeckBySlug"] ?? null;
|
|
770
|
+
});
|
|
771
|
+
}
|
|
750
772
|
/**
|
|
751
773
|
* Fetch a hosted deck by external reference for the current API application.
|
|
752
774
|
*/
|
|
@@ -775,6 +797,68 @@ var DecksResource = class extends BaseResource {
|
|
|
775
797
|
nextPageLoader: async (cursor) => this.listMine({ ...options, after: cursor })
|
|
776
798
|
});
|
|
777
799
|
}
|
|
800
|
+
/**
|
|
801
|
+
* Fetch one immutable published deck version.
|
|
802
|
+
*/
|
|
803
|
+
async fetchVersion(id, options = {}) {
|
|
804
|
+
const key = this.cacheKey("decks", "fetchVersion", { id });
|
|
805
|
+
return this.withCache(key, "decks", options, async () => {
|
|
806
|
+
const { query } = core.QueryBuilder.deckVersion();
|
|
807
|
+
const result = await this.connection.execute(query, { id });
|
|
808
|
+
return result["deckVersion"] ?? null;
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* List immutable published versions for a deck.
|
|
813
|
+
*/
|
|
814
|
+
async listVersions(deckId, options = {}) {
|
|
815
|
+
const { query, variables: pageVariables } = core.QueryBuilder.deckVersions({
|
|
816
|
+
first: options.first,
|
|
817
|
+
after: options.after
|
|
818
|
+
});
|
|
819
|
+
const variables = { deckId, ...pageVariables };
|
|
820
|
+
const key = this.cacheKey("decks", "listVersions", variables);
|
|
821
|
+
const data = await this.withCache(key, "decks", options, async () => {
|
|
822
|
+
const result = await this.connection.execute(query, variables);
|
|
823
|
+
return result["deckVersions"];
|
|
824
|
+
});
|
|
825
|
+
return new core.Collection(data, {
|
|
826
|
+
nextPageLoader: async (cursor) => this.listVersions(deckId, { ...options, after: cursor })
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Fetch current draft data using a revocable preview token.
|
|
831
|
+
*/
|
|
832
|
+
async preview(token, options = {}) {
|
|
833
|
+
const key = this.cacheKey("decks", "preview", { token });
|
|
834
|
+
return this.withCache(key, "decks", options, async () => {
|
|
835
|
+
const { query } = core.QueryBuilder.deckPreview();
|
|
836
|
+
const result = await this.connection.execute(query, { token });
|
|
837
|
+
return result["deckPreview"] ?? null;
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* List collaborators for a deck.
|
|
842
|
+
*/
|
|
843
|
+
async listCollaborators(deckId, options = {}) {
|
|
844
|
+
const key = this.cacheKey("decks", "listCollaborators", { deckId });
|
|
845
|
+
return this.withCache(key, "decks", options, async () => {
|
|
846
|
+
const { query } = core.QueryBuilder.deckCollaborators();
|
|
847
|
+
const result = await this.connection.execute(query, { deckId });
|
|
848
|
+
return result["deckCollaborators"];
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* List draft preview tokens for a deck.
|
|
853
|
+
*/
|
|
854
|
+
async listPreviewTokens(deckId, options = {}) {
|
|
855
|
+
const key = this.cacheKey("decks", "listPreviewTokens", { deckId });
|
|
856
|
+
return this.withCache(key, "decks", options, async () => {
|
|
857
|
+
const { query } = core.QueryBuilder.deckPreviewTokens();
|
|
858
|
+
const result = await this.connection.execute(query, { deckId });
|
|
859
|
+
return result["deckPreviewTokens"];
|
|
860
|
+
});
|
|
861
|
+
}
|
|
778
862
|
/**
|
|
779
863
|
* Create a hosted deck.
|
|
780
864
|
*/
|
|
@@ -801,6 +885,50 @@ var DecksResource = class extends BaseResource {
|
|
|
801
885
|
const result = await this.connection.execute(query, { id });
|
|
802
886
|
return Boolean(result["deckDelete"]);
|
|
803
887
|
}
|
|
888
|
+
/**
|
|
889
|
+
* Publish the current draft as an immutable deck version.
|
|
890
|
+
*/
|
|
891
|
+
async publish(id, input = {}) {
|
|
892
|
+
const { query } = core.QueryBuilder.publishDeck();
|
|
893
|
+
const variables = core.QueryBuilder.deckPublishVariables(id, input);
|
|
894
|
+
const result = await this.connection.execute(query, variables);
|
|
895
|
+
return result["deckPublish"];
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Create or update a deck collaborator.
|
|
899
|
+
*/
|
|
900
|
+
async upsertCollaborator(deckId, accountId, role) {
|
|
901
|
+
const { query } = core.QueryBuilder.upsertDeckCollaborator();
|
|
902
|
+
const variables = core.QueryBuilder.deckCollaboratorVariables(deckId, accountId, role);
|
|
903
|
+
const result = await this.connection.execute(query, variables);
|
|
904
|
+
return result["deckCollaboratorUpsert"];
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Remove a deck collaborator.
|
|
908
|
+
*/
|
|
909
|
+
async removeCollaborator(deckId, accountId) {
|
|
910
|
+
const { query } = core.QueryBuilder.removeDeckCollaborator();
|
|
911
|
+
const variables = core.QueryBuilder.deckCollaboratorVariables(deckId, accountId);
|
|
912
|
+
const result = await this.connection.execute(query, variables);
|
|
913
|
+
return Boolean(result["deckCollaboratorRemove"]);
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Create a revocable draft preview token.
|
|
917
|
+
*/
|
|
918
|
+
async createPreviewToken(input) {
|
|
919
|
+
const { query } = core.QueryBuilder.createDeckPreviewToken();
|
|
920
|
+
const variables = core.QueryBuilder.deckPreviewTokenCreateVariables(input);
|
|
921
|
+
const result = await this.connection.execute(query, variables);
|
|
922
|
+
return result["deckPreviewTokenCreate"];
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Revoke a draft preview token.
|
|
926
|
+
*/
|
|
927
|
+
async revokePreviewToken(id) {
|
|
928
|
+
const { query } = core.QueryBuilder.revokeDeckPreviewToken();
|
|
929
|
+
const result = await this.connection.execute(query, { id });
|
|
930
|
+
return Boolean(result["deckPreviewTokenRevoke"]);
|
|
931
|
+
}
|
|
804
932
|
/**
|
|
805
933
|
* Hydrate third-party-owned deck entries without storing them in CardDB.
|
|
806
934
|
*/
|
|
@@ -826,7 +954,11 @@ var DecksResource = class extends BaseResource {
|
|
|
826
954
|
});
|
|
827
955
|
return result["fetchRecordsByIdentifier"];
|
|
828
956
|
});
|
|
829
|
-
const recordsByIdentifier = recordsByDeckIdentifier(
|
|
957
|
+
const recordsByIdentifier = recordsByDeckIdentifier(
|
|
958
|
+
records,
|
|
959
|
+
identifiers,
|
|
960
|
+
options.identifierField
|
|
961
|
+
);
|
|
830
962
|
return options.entries.map((entry) => ({
|
|
831
963
|
...entry,
|
|
832
964
|
record: recordsByIdentifier.get(entry.identifier) ?? null
|