@matvdt/js-toolkit 0.0.1-canary.21 → 0.0.1-canary.23
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GlobalSlug } from 'payload';
|
|
2
|
-
import { payload } from './payload';
|
|
2
|
+
import { payload, FindGlobalOptions } from './payload';
|
|
3
3
|
type BaseGlobalMethods<TSlug extends GlobalSlug> = {
|
|
4
|
-
get: () => ReturnType<typeof payload.global<TSlug>>;
|
|
4
|
+
get: (options?: FindGlobalOptions) => ReturnType<typeof payload.global<TSlug>>;
|
|
5
5
|
};
|
|
6
6
|
export declare function createGlobal<TSlug extends GlobalSlug, TExtend extends Record<string, (...args: any[]) => any> = {}>(slug: TSlug, extend?: (base: BaseGlobalMethods<TSlug>) => TExtend): BaseGlobalMethods<TSlug> & TExtend;
|
|
7
7
|
export {};
|
|
@@ -42,13 +42,13 @@ function withCache(collection, method, args, tags, fn) {
|
|
|
42
42
|
return (0, import_cache.unstable_cache)(fn, cacheKey(collection, method, args), { tags })();
|
|
43
43
|
}
|
|
44
44
|
function revalidateCollection(collection) {
|
|
45
|
-
(0, import_cache.revalidateTag)(`collection:${collection}`,
|
|
45
|
+
(0, import_cache.revalidateTag)(`collection:${collection}`, { expire: 0 });
|
|
46
46
|
}
|
|
47
47
|
function revalidateDoc(collection, id) {
|
|
48
|
-
(0, import_cache.revalidateTag)(`doc:${collection}:${id}`,
|
|
48
|
+
(0, import_cache.revalidateTag)(`doc:${collection}:${id}`, { expire: 0 });
|
|
49
49
|
}
|
|
50
50
|
function revalidateGlobal(slug) {
|
|
51
|
-
(0, import_cache.revalidateTag)(`global:${slug}`,
|
|
51
|
+
(0, import_cache.revalidateTag)(`global:${slug}`, { expire: 0 });
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// src/payload-cms/server/payload.ts
|
|
@@ -186,10 +186,10 @@ var payload = {
|
|
|
186
186
|
revalidateCollection(collection);
|
|
187
187
|
return result;
|
|
188
188
|
},
|
|
189
|
-
global: async (slug) => {
|
|
190
|
-
return withCache("global", slug, [], [`global:${slug}`], async () => {
|
|
189
|
+
global: async (slug, options) => {
|
|
190
|
+
return withCache("global", slug, [options], [`global:${slug}`], async () => {
|
|
191
191
|
const client = await getClient();
|
|
192
|
-
return client.findGlobal({ slug });
|
|
192
|
+
return client.findGlobal({ ...options, slug });
|
|
193
193
|
});
|
|
194
194
|
},
|
|
195
195
|
aggregate: async (collection, pipeline, options) => {
|
|
@@ -224,7 +224,7 @@ function createCollection(collection, extend) {
|
|
|
224
224
|
// src/payload-cms/server/create-global.ts
|
|
225
225
|
function createGlobal(slug, extend) {
|
|
226
226
|
const base = {
|
|
227
|
-
get: () => payload.global(slug)
|
|
227
|
+
get: (options) => payload.global(slug, options)
|
|
228
228
|
};
|
|
229
229
|
const extended = extend ? extend(base) : void 0;
|
|
230
230
|
return {
|
|
@@ -7,13 +7,13 @@ function withCache(collection, method, args, tags, fn) {
|
|
|
7
7
|
return unstable_cache(fn, cacheKey(collection, method, args), { tags })();
|
|
8
8
|
}
|
|
9
9
|
function revalidateCollection(collection) {
|
|
10
|
-
revalidateTag(`collection:${collection}`,
|
|
10
|
+
revalidateTag(`collection:${collection}`, { expire: 0 });
|
|
11
11
|
}
|
|
12
12
|
function revalidateDoc(collection, id) {
|
|
13
|
-
revalidateTag(`doc:${collection}:${id}`,
|
|
13
|
+
revalidateTag(`doc:${collection}:${id}`, { expire: 0 });
|
|
14
14
|
}
|
|
15
15
|
function revalidateGlobal(slug) {
|
|
16
|
-
revalidateTag(`global:${slug}`,
|
|
16
|
+
revalidateTag(`global:${slug}`, { expire: 0 });
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// src/payload-cms/server/payload.ts
|
|
@@ -151,10 +151,10 @@ var payload = {
|
|
|
151
151
|
revalidateCollection(collection);
|
|
152
152
|
return result;
|
|
153
153
|
},
|
|
154
|
-
global: async (slug) => {
|
|
155
|
-
return withCache("global", slug, [], [`global:${slug}`], async () => {
|
|
154
|
+
global: async (slug, options) => {
|
|
155
|
+
return withCache("global", slug, [options], [`global:${slug}`], async () => {
|
|
156
156
|
const client = await getClient();
|
|
157
|
-
return client.findGlobal({ slug });
|
|
157
|
+
return client.findGlobal({ ...options, slug });
|
|
158
158
|
});
|
|
159
159
|
},
|
|
160
160
|
aggregate: async (collection, pipeline, options) => {
|
|
@@ -189,7 +189,7 @@ function createCollection(collection, extend) {
|
|
|
189
189
|
// src/payload-cms/server/create-global.ts
|
|
190
190
|
function createGlobal(slug, extend) {
|
|
191
191
|
const base = {
|
|
192
|
-
get: () => payload.global(slug)
|
|
192
|
+
get: (options) => payload.global(slug, options)
|
|
193
193
|
};
|
|
194
194
|
const extended = extend ? extend(base) : void 0;
|
|
195
195
|
return {
|
|
@@ -6,6 +6,7 @@ export type FindOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>
|
|
|
6
6
|
export type FindByIDOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['findByID']>[0], 'collection' | 'id'>;
|
|
7
7
|
export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
|
|
8
8
|
export type DeleteOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['delete']>[0], 'collection' | 'id' | 'where'>;
|
|
9
|
+
export type FindGlobalOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['findGlobal']>[0], 'slug'>;
|
|
9
10
|
export type UpdateData = Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0]['data'];
|
|
10
11
|
export declare const payload: {
|
|
11
12
|
findOne: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
@@ -18,7 +19,7 @@ export declare const payload: {
|
|
|
18
19
|
updateMany: <TSlug extends CollectionSlug>(collection: TSlug, where: Where, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").BulkOperationResult<TSlug, import("payload").SelectExcludeType | import("payload").SelectIncludeType>>;
|
|
19
20
|
delete: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: DeleteOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
|
|
20
21
|
deleteMany: <TSlug extends CollectionSlug>(collection: TSlug, where: Where, options?: DeleteOptions) => Promise<import("payload").BulkOperationResult<TSlug, import("payload").SelectExcludeType | import("payload").SelectIncludeType>>;
|
|
21
|
-
global: <TSlug extends GlobalSlug>(slug: TSlug) => Promise<DataFromGlobalSlug<TSlug>>;
|
|
22
|
+
global: <TSlug extends GlobalSlug>(slug: TSlug, options?: FindGlobalOptions) => Promise<DataFromGlobalSlug<TSlug>>;
|
|
22
23
|
aggregate: <TSlug extends CollectionSlug, TData = any>(collection: TSlug, pipeline?: PipelineStage[], options?: AggregateOptions) => Promise<Aggregate<TData[]>>;
|
|
23
24
|
raw: () => Promise<import("payload").BasePayload>;
|
|
24
25
|
};
|