@sanity/blueprints 0.23.0 → 0.23.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.
Files changed (47) hide show
  1. package/dist/definers/functions/base-event.d.ts +2 -0
  2. package/dist/definers/functions/base-event.js +2 -0
  3. package/dist/definers/functions/base-event.js.map +1 -0
  4. package/dist/definers/functions/document.d.ts +26 -0
  5. package/dist/definers/functions/document.js +43 -0
  6. package/dist/definers/functions/document.js.map +1 -0
  7. package/dist/definers/functions/event.d.ts +20 -0
  8. package/dist/definers/functions/event.js +30 -0
  9. package/dist/definers/functions/event.js.map +1 -0
  10. package/dist/definers/functions/index.d.ts +15 -0
  11. package/dist/definers/functions/index.js +34 -0
  12. package/dist/definers/functions/index.js.map +1 -0
  13. package/dist/definers/functions/media-library.d.ts +23 -0
  14. package/dist/definers/functions/media-library.js +83 -0
  15. package/dist/definers/functions/media-library.js.map +1 -0
  16. package/dist/definers/functions/pipeline.d.ts +26 -0
  17. package/dist/definers/functions/pipeline.js +41 -0
  18. package/dist/definers/functions/pipeline.js.map +1 -0
  19. package/dist/definers/functions/queue.d.ts +30 -0
  20. package/dist/definers/functions/queue.js +47 -0
  21. package/dist/definers/functions/queue.js.map +1 -0
  22. package/dist/definers/functions/scheduled.d.ts +46 -0
  23. package/dist/definers/functions/scheduled.js +91 -0
  24. package/dist/definers/functions/scheduled.js.map +1 -0
  25. package/dist/definers/functions/sync-tag-invalidate.d.ts +31 -0
  26. package/dist/definers/functions/sync-tag-invalidate.js +43 -0
  27. package/dist/definers/functions/sync-tag-invalidate.js.map +1 -0
  28. package/dist/index.d.ts +8 -1
  29. package/dist/index.js +8 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/types/functions/index.d.ts +51 -31
  32. package/package.json +1 -1
  33. package/src/definers/functions/base-event.ts +4 -0
  34. package/src/definers/functions/document.ts +129 -0
  35. package/src/definers/functions/event.ts +32 -0
  36. package/src/definers/functions/index.ts +39 -0
  37. package/src/definers/functions/media-library.ts +98 -0
  38. package/src/definers/functions/pipeline.ts +42 -0
  39. package/src/definers/functions/queue.ts +49 -0
  40. package/src/definers/functions/scheduled.ts +112 -0
  41. package/src/definers/functions/sync-tag-invalidate.ts +51 -0
  42. package/src/index.ts +8 -1
  43. package/src/types/functions/index.ts +64 -43
  44. package/dist/definers/functions.d.ts +0 -210
  45. package/dist/definers/functions.js +0 -381
  46. package/dist/definers/functions.js.map +0 -1
  47. package/src/definers/functions.ts +0 -540
@@ -0,0 +1,2 @@
1
+ import type { BlueprintFunctionBaseResourceEvent } from '../../index.js';
2
+ export declare const BASE_EVENT_KEYS: Set<keyof BlueprintFunctionBaseResourceEvent>;
@@ -0,0 +1,2 @@
1
+ export const BASE_EVENT_KEYS = new Set(['on', 'filter', 'projection', 'includeDrafts']);
2
+ //# sourceMappingURL=base-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-event.js","sourceRoot":"","sources":["../../../src/definers/functions/base-event.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAuB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { type BlueprintDocumentFunctionConfig, type BlueprintDocumentFunctionResource, type BlueprintDocumentFunctionResourceEvent } from '../../index.js';
2
+ /**
3
+ * Defines a function that is triggered by document events in Sanity datasets.
4
+ *
5
+ * ```ts
6
+ * defineDocumentFunction({
7
+ * name: 'my-document-function',
8
+ * event: {
9
+ * on: ['create', 'update'],
10
+ * filter: "_type == 'post'",
11
+ * projection: "{_id, title, slug}",
12
+ * },
13
+ * })
14
+ * ```
15
+ * @param functionConfig The configuration for the document function
16
+ * @public
17
+ * @category Definers
18
+ * @expandType BlueprintDocumentFunctionConfig
19
+ * @returns The validated document function resource
20
+ */
21
+ export declare function defineDocumentFunction(functionConfig: BlueprintDocumentFunctionConfig): BlueprintDocumentFunctionResource;
22
+ /**
23
+ * @deprecated Define event properties under the 'event' key instead of specifying them at the top level
24
+ * @hidden
25
+ */
26
+ export declare function defineDocumentFunction(functionConfig: BlueprintDocumentFunctionConfig & Partial<BlueprintDocumentFunctionResourceEvent>): BlueprintDocumentFunctionResource;
@@ -0,0 +1,43 @@
1
+ import { validateDocumentFunction, } from '../../index.js';
2
+ import { runValidation } from '../../utils/validation.js';
3
+ import { BASE_EVENT_KEYS } from './base-event.js';
4
+ import { defineFunction } from './index.js';
5
+ const DOCUMENT_EVENT_KEYS = new Set(['includeAllVersions', 'resource', ...BASE_EVENT_KEYS.values()]);
6
+ export function defineDocumentFunction(functionConfig) {
7
+ let { name, src, event, timeout, memory, env, robotToken, project, runtime, ...maybeEvent } = functionConfig;
8
+ // event validation and normalization
9
+ if (event) {
10
+ // `event` was specified, but event keys (aggregated in `maybeEvent`) were also specified at the top level. ambiguous and deprecated usage.
11
+ const duplicateKeys = Array.from(DOCUMENT_EVENT_KEYS).filter((key) => key in maybeEvent);
12
+ if (duplicateKeys.length > 0) {
13
+ throw new Error(`\`event\` properties should be specified under the \`event\` key - specifying them at the top level is deprecated. The following keys were specified at the top level: ${duplicateKeys.map((k) => `\`${k}\``).join(', ')}`);
14
+ }
15
+ event = buildDocumentFunctionEvent(event);
16
+ }
17
+ else {
18
+ event = buildDocumentFunctionEvent(maybeEvent);
19
+ // deprecated usage of putting event properties at the top level, warn about this.
20
+ console.warn('⚠️ Deprecated usage of `defineDocumentFunction`: prefer to put `event` properties under the `event` key rather than at the top level.');
21
+ }
22
+ const functionResource = {
23
+ ...defineFunction(functionConfig, { skipValidation: true }),
24
+ type: 'sanity.function.document',
25
+ event,
26
+ };
27
+ runValidation(() => validateDocumentFunction(functionResource));
28
+ return functionResource;
29
+ }
30
+ /**
31
+ * Builds a document function event configuration from partial event properties.
32
+ * Filters out non-event properties and applies defaults.
33
+ * @param event Partial document function event configuration
34
+ * @returns Complete document function event configuration
35
+ */
36
+ function buildDocumentFunctionEvent(event) {
37
+ const cleanEvent = Object.fromEntries(Object.entries(event).filter(([key]) => DOCUMENT_EVENT_KEYS.has(key)));
38
+ return {
39
+ on: cleanEvent.on || ['publish'],
40
+ ...cleanEvent,
41
+ };
42
+ }
43
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.js","sourceRoot":"","sources":["../../../src/definers/functions/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,wBAAwB,GACzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAGzC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B,CAAC,oBAAoB,EAAE,UAAU,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAmE9H,MAAM,UAAU,sBAAsB,CACpC,cAAiG;IAEjG,IAAI,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,UAAU,EAAC,GAAG,cAAc,CAAA;IAE1G,qCAAqC;IACrC,IAAI,KAAK,EAAE,CAAC;QACV,2IAA2I;QAC3I,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,UAAU,CAAC,CAAA;QACxF,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,0KAA0K,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC5N,CAAA;QACH,CAAC;QAED,KAAK,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAA;IAC3C,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,0BAA0B,CAAC,UAAU,CAAC,CAAA;QAC9C,kFAAkF;QAClF,OAAO,CAAC,IAAI,CACV,uIAAuI,CACxI,CAAA;IACH,CAAC;IAED,MAAM,gBAAgB,GAAsC;QAC1D,GAAG,cAAc,CAAC,cAAc,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;QACzD,IAAI,EAAE,0BAA0B;QAChC,KAAK;KACN,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAE/D,OAAO,gBAAgB,CAAA;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,0BAA0B,CAAC,KAAsD;IACxF,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAA+B,CAAC,CAAC,CAC/C,CAAA;IAEpD,OAAO;QACL,EAAE,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC;QAChC,GAAG,UAAU;KACd,CAAA;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type BlueprintEventFunctionConfig, type BlueprintEventFunctionResource } from '../../index.js';
2
+ /**
3
+ * Defines a function that provide event behaviour.
4
+ *
5
+ * @remarks
6
+ * A barebones event function
7
+ * ```ts
8
+ * defineEventFunction({
9
+ * name: 'send-email',
10
+ * })
11
+ * ```
12
+ * @public
13
+ * @alpha Deploying Event Functions via Blueprints is experimental. This feature is not available publicly yet.
14
+ * @hidden
15
+ * @category Definers
16
+ * @expandType BlueprintEventFunctionConfig
17
+ * @param functionConfig The configuration for the event function
18
+ * @returns The validated event function resource
19
+ */
20
+ export declare function defineEventFunction(functionConfig: BlueprintEventFunctionConfig): BlueprintEventFunctionResource;
@@ -0,0 +1,30 @@
1
+ import { validateEventFunction } from '../../index.js';
2
+ import { runValidation } from '../../utils/validation.js';
3
+ import { defineFunction } from './index.js';
4
+ /**
5
+ * Defines a function that provide event behaviour.
6
+ *
7
+ * @remarks
8
+ * A barebones event function
9
+ * ```ts
10
+ * defineEventFunction({
11
+ * name: 'send-email',
12
+ * })
13
+ * ```
14
+ * @public
15
+ * @alpha Deploying Event Functions via Blueprints is experimental. This feature is not available publicly yet.
16
+ * @hidden
17
+ * @category Definers
18
+ * @expandType BlueprintEventFunctionConfig
19
+ * @param functionConfig The configuration for the event function
20
+ * @returns The validated event function resource
21
+ */
22
+ export function defineEventFunction(functionConfig) {
23
+ const functionResource = {
24
+ ...defineFunction(functionConfig, { skipValidation: true }),
25
+ type: 'sanity.function.event',
26
+ };
27
+ runValidation(() => validateEventFunction(functionResource));
28
+ return functionResource;
29
+ }
30
+ //# sourceMappingURL=event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../../../src/definers/functions/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyE,qBAAqB,EAAC,MAAM,gBAAgB,CAAA;AAC5H,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB,CAAC,cAA4C;IAC9E,MAAM,gBAAgB,GAAmC;QACvD,GAAG,cAAc,CAAC,cAAc,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;QACzD,IAAI,EAAE,uBAAuB;KAC9B,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAE5D,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type BlueprintBaseFunctionConfig, type BlueprintBaseFunctionResource } from '../../index.js';
2
+ /**
3
+ * Defines a base function resource with common properties.
4
+ *
5
+ * @param functionConfig The configuration for the function
6
+ * @param options Optional configuration including validation options
7
+ * @category Definers
8
+ * @internal
9
+ * @expandType BlueprintBaseFunctionConfig
10
+ * @returns The validated function resource
11
+ */
12
+ export declare function defineFunction(functionConfig: BlueprintBaseFunctionConfig, options?: {
13
+ skipValidation?: boolean;
14
+ scopeType?: 'organization';
15
+ }): BlueprintBaseFunctionResource;
@@ -0,0 +1,34 @@
1
+ import { validateFunction } from '../../index.js';
2
+ import { runValidation } from '../../utils/validation.js';
3
+ /**
4
+ * Defines a base function resource with common properties.
5
+ *
6
+ * @param functionConfig The configuration for the function
7
+ * @param options Optional configuration including validation options
8
+ * @category Definers
9
+ * @internal
10
+ * @expandType BlueprintBaseFunctionConfig
11
+ * @returns The validated function resource
12
+ */
13
+ export function defineFunction(functionConfig, options) {
14
+ const { name, displayName, src, timeout, memory, env, robotToken, project, runtime, lifecycle } = functionConfig;
15
+ const functionResource = {
16
+ type: 'sanity.function.document',
17
+ name,
18
+ src: src ?? `functions/${name}`,
19
+ displayName,
20
+ timeout,
21
+ memory,
22
+ env,
23
+ robotToken,
24
+ runtime,
25
+ };
26
+ if (options?.scopeType !== 'organization' && project)
27
+ functionResource.project = project;
28
+ if (lifecycle)
29
+ functionResource.lifecycle = lifecycle;
30
+ if (options?.skipValidation !== true)
31
+ runValidation(() => validateFunction(functionResource));
32
+ return functionResource;
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definers/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuE,gBAAgB,EAAC,MAAM,gBAAgB,CAAA;AACrH,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AAEvD;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,cAA2C,EAC3C,OAAgE;IAEhE,MAAM,EAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAC,GAAG,cAAc,CAAA;IAE9G,MAAM,gBAAgB,GAAkC;QACtD,IAAI,EAAE,0BAA0B;QAChC,IAAI;QACJ,GAAG,EAAE,GAAG,IAAI,aAAa,IAAI,EAAE;QAC/B,WAAW;QACX,OAAO;QACP,MAAM;QACN,GAAG;QACH,UAAU;QACV,OAAO;KACR,CAAA;IAED,IAAI,OAAO,EAAE,SAAS,KAAK,cAAc,IAAI,OAAO;QAAE,gBAAgB,CAAC,OAAO,GAAG,OAAO,CAAA;IAExF,IAAI,SAAS;QAAE,gBAAgB,CAAC,SAAS,GAAG,SAAS,CAAA;IAErD,IAAI,OAAO,EAAE,cAAc,KAAK,IAAI;QAAE,aAAa,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAE7F,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type BlueprintMediaLibraryAssetFunctionConfig, type BlueprintMediaLibraryAssetFunctionResource } from '../../index.js';
2
+ /**
3
+ * Defines a function that is triggered by media library events.
4
+ *
5
+ * ```ts
6
+ * defineMediaLibraryAssetFunction({
7
+ * name: 'my-media-library-function',
8
+ * event: {
9
+ * on: ['create'],
10
+ * resource: {
11
+ * type: 'media-library',
12
+ * id: 'my-media-library-id',
13
+ * },
14
+ * },
15
+ * })
16
+ * ```
17
+ * @param functionConfig The configuration for the media library asset function
18
+ * @public
19
+ * @category Definers
20
+ * @expandType BlueprintMediaLibraryAssetFunctionConfig
21
+ * @returns The validated media library asset function resource
22
+ */
23
+ export declare function defineMediaLibraryAssetFunction(functionConfig: BlueprintMediaLibraryAssetFunctionConfig): BlueprintMediaLibraryAssetFunctionResource;
@@ -0,0 +1,83 @@
1
+ import { validateMediaLibraryAssetFunction, } from '../../index.js';
2
+ import { runValidation } from '../../utils/validation.js';
3
+ import { BASE_EVENT_KEYS } from './base-event.js';
4
+ import { defineFunction } from './index.js';
5
+ const MEDIA_LIBRARY_EVENT_KEYS = new Set(['resource', ...BASE_EVENT_KEYS.values()]);
6
+ /*
7
+ * FUTURE example (move below @example when ready)
8
+ * @example With robot token reference
9
+ * ```ts
10
+ * defineRobotToken({
11
+ * name: 'media-robot',
12
+ * memberships: [{
13
+ * resourceType: 'project',
14
+ * resourceId: projectId,
15
+ * roleNames: ['editor'],
16
+ * }],
17
+ * })
18
+ *
19
+ * defineMediaLibraryAssetFunction({
20
+ * name: 'process-uploads',
21
+ * src: 'functions/process-uploads-v2',
22
+ * robotToken: '$.resources.media-robot',
23
+ * event: {
24
+ * on: ['create', 'update'],
25
+ * resource: {
26
+ * type: 'media-library',
27
+ * id: 'my-media-library-id',
28
+ * },
29
+ * filter: "type == 'image'",
30
+ * projection: "{_id}",
31
+ * },
32
+ * env: {
33
+ * CDN_BUCKET: 'my-cdn-bucket',
34
+ * },
35
+ * })
36
+ * ```
37
+ */
38
+ /**
39
+ * Defines a function that is triggered by media library events.
40
+ *
41
+ * ```ts
42
+ * defineMediaLibraryAssetFunction({
43
+ * name: 'my-media-library-function',
44
+ * event: {
45
+ * on: ['create'],
46
+ * resource: {
47
+ * type: 'media-library',
48
+ * id: 'my-media-library-id',
49
+ * },
50
+ * },
51
+ * })
52
+ * ```
53
+ * @param functionConfig The configuration for the media library asset function
54
+ * @public
55
+ * @category Definers
56
+ * @expandType BlueprintMediaLibraryAssetFunctionConfig
57
+ * @returns The validated media library asset function resource
58
+ */
59
+ export function defineMediaLibraryAssetFunction(functionConfig) {
60
+ const { event } = functionConfig;
61
+ const functionResource = {
62
+ ...defineFunction(functionConfig, { skipValidation: true }),
63
+ type: 'sanity.function.media-library.asset',
64
+ event: buildMediaLibraryFunctionEvent(event),
65
+ };
66
+ runValidation(() => validateMediaLibraryAssetFunction(functionResource));
67
+ return functionResource;
68
+ }
69
+ /**
70
+ * Builds a media library function event configuration.
71
+ * Filters out non-event properties and applies defaults.
72
+ * @param event Media library function event configuration
73
+ * @returns Complete media library function event configuration
74
+ */
75
+ function buildMediaLibraryFunctionEvent(event) {
76
+ const cleanEvent = Object.fromEntries(Object.entries(event).filter(([key]) => MEDIA_LIBRARY_EVENT_KEYS.has(key)));
77
+ const fullEvent = {
78
+ on: cleanEvent.on || ['publish'],
79
+ ...cleanEvent,
80
+ };
81
+ return fullEvent;
82
+ }
83
+ //# sourceMappingURL=media-library.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-library.js","sourceRoot":"","sources":["../../../src/definers/functions/media-library.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iCAAiC,GAClC,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAGzC,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAA+B,CAAC,UAAU,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AACjH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,+BAA+B,CAC7C,cAAwD;IAExD,MAAM,EAAC,KAAK,EAAC,GAAG,cAAc,CAAA;IAE9B,MAAM,gBAAgB,GAA+C;QACnE,GAAG,cAAc,CAAC,cAAc,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;QACzD,IAAI,EAAE,qCAAqC;QAC3C,KAAK,EAAE,8BAA8B,CAAC,KAAK,CAAC;KAC7C,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,iCAAiC,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAExE,OAAO,gBAAgB,CAAA;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,8BAA8B,CAAC,KAAiD;IACvF,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,wBAAwB,CAAC,GAAG,CAAC,GAAmC,CAAC,CAAC,CAC7D,CAAA;IAE/C,MAAM,SAAS,GAAG;QAChB,EAAE,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC;QAChC,GAAG,UAAU;KACd,CAAA;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type BlueprintPipelineConfig, type BlueprintPipelineResource } from '../../index.js';
2
+ /**
3
+ * Defines a pipeline function resource.
4
+ *
5
+ * @remarks
6
+ *
7
+ * ```ts
8
+ * definePipeline({
9
+ * name: 'daily-cleanup',
10
+ * event: {type: 'document', on: ['create'], filter: "_type == 'post'"},
11
+ * concurrency: 5,
12
+ * debounce: 10,
13
+ * debounceKey: 'document._id',
14
+ * })
15
+ * ```
16
+ *
17
+ *
18
+ * @param functionConfig The configuration for the function
19
+ * @category Definers
20
+ * @alpha Deploying Pipeline Functions via Blueprints is experimental. This feature is not available publicly yet.
21
+ * @public
22
+ * @hidden
23
+ * @expandType BlueprintPipelineConfig
24
+ * @returns The validated pipeline function resource
25
+ */
26
+ export declare function definePipeline(functionConfig: BlueprintPipelineConfig): BlueprintPipelineResource;
@@ -0,0 +1,41 @@
1
+ import { validatePipelineFunction } from '../../index.js';
2
+ import { runValidation } from '../../utils/validation.js';
3
+ import { defineFunction } from './index.js';
4
+ /**
5
+ * Defines a pipeline function resource.
6
+ *
7
+ * @remarks
8
+ *
9
+ * ```ts
10
+ * definePipeline({
11
+ * name: 'daily-cleanup',
12
+ * event: {type: 'document', on: ['create'], filter: "_type == 'post'"},
13
+ * concurrency: 5,
14
+ * debounce: 10,
15
+ * debounceKey: 'document._id',
16
+ * })
17
+ * ```
18
+ *
19
+ *
20
+ * @param functionConfig The configuration for the function
21
+ * @category Definers
22
+ * @alpha Deploying Pipeline Functions via Blueprints is experimental. This feature is not available publicly yet.
23
+ * @public
24
+ * @hidden
25
+ * @expandType BlueprintPipelineConfig
26
+ * @returns The validated pipeline function resource
27
+ */
28
+ export function definePipeline(functionConfig) {
29
+ const { name, event, concurrency, debounce, debounceKey, src } = functionConfig;
30
+ const functionResource = {
31
+ ...defineFunction({ ...functionConfig, src: src ?? `functions/${name}` }, { skipValidation: true }),
32
+ type: 'sanity.function.pipeline',
33
+ ...(event !== undefined && { event }),
34
+ ...(concurrency !== undefined && { concurrency }),
35
+ ...(debounce !== undefined && { debounce }),
36
+ ...(debounceKey !== undefined && { debounceKey }),
37
+ };
38
+ runValidation(() => validatePipelineFunction(functionResource));
39
+ return functionResource;
40
+ }
41
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../../src/definers/functions/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+D,wBAAwB,EAAC,MAAM,gBAAgB,CAAA;AACrH,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,cAAc,CAAC,cAAuC;IACpE,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAC,GAAG,cAAc,CAAA;IAC7E,MAAM,gBAAgB,GAA8B;QAClD,GAAG,cAAc,CAAC,EAAC,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,aAAa,IAAI,EAAE,EAAC,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;QAC/F,IAAI,EAAE,0BAA0B;QAChC,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAC,KAAK,EAAC,CAAC;QACnC,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI,EAAC,WAAW,EAAC,CAAC;QAC/C,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAC,QAAQ,EAAC,CAAC;QACzC,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI,EAAC,WAAW,EAAC,CAAC;KAChD,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAC/D,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type BlueprintQueueFunctionConfig, type BlueprintQueueFunctionResource } from '../../index.js';
2
+ /**
3
+ * Defines a function that provide queueing behaviour.
4
+ *
5
+ * @remarks
6
+ * Using the reasonable defaults of concurrency: 1, fifo: true, and dlq: true
7
+ * ```ts
8
+ * defineQueueFunction({
9
+ * name: 'send-email',
10
+ * })
11
+ * ```
12
+ *
13
+ * Specifying a concurrency of 5
14
+ * ```ts
15
+ * defineQueueFunction({
16
+ * name: 'bustin-caches',
17
+ * concurrency: 5,
18
+ * fifo: true,
19
+ * dlq: true,
20
+ * })
21
+ * ```
22
+ * @public
23
+ * @alpha Deploying Queue Functions via Blueprints is experimental. This feature is not available publicly yet.
24
+ * @hidden
25
+ * @category Definers
26
+ * @expandType BlueprintQueueFunctionConfig
27
+ * @param functionConfig The configuration for the queue function
28
+ * @returns The validated queue function resource
29
+ */
30
+ export declare function defineQueueFunction(functionConfig: BlueprintQueueFunctionConfig): BlueprintQueueFunctionResource;
@@ -0,0 +1,47 @@
1
+ import { validateQueueFunction } from '../../index.js';
2
+ import { runValidation } from '../../utils/validation.js';
3
+ import { defineFunction } from './index.js';
4
+ /**
5
+ * Defines a function that provide queueing behaviour.
6
+ *
7
+ * @remarks
8
+ * Using the reasonable defaults of concurrency: 1, fifo: true, and dlq: true
9
+ * ```ts
10
+ * defineQueueFunction({
11
+ * name: 'send-email',
12
+ * })
13
+ * ```
14
+ *
15
+ * Specifying a concurrency of 5
16
+ * ```ts
17
+ * defineQueueFunction({
18
+ * name: 'bustin-caches',
19
+ * concurrency: 5,
20
+ * fifo: true,
21
+ * dlq: true,
22
+ * })
23
+ * ```
24
+ * @public
25
+ * @alpha Deploying Queue Functions via Blueprints is experimental. This feature is not available publicly yet.
26
+ * @hidden
27
+ * @category Definers
28
+ * @expandType BlueprintQueueFunctionConfig
29
+ * @param functionConfig The configuration for the queue function
30
+ * @returns The validated queue function resource
31
+ */
32
+ export function defineQueueFunction(functionConfig) {
33
+ const { concurrency = 1, fifo = true, dlq = true, debounce, debounceKey, event } = functionConfig;
34
+ const functionResource = {
35
+ ...defineFunction(functionConfig, { skipValidation: true }),
36
+ type: 'sanity.function.queue',
37
+ ...(concurrency !== undefined && { concurrency }),
38
+ ...(debounce !== undefined && { debounce }),
39
+ ...(debounceKey !== undefined && { debounceKey }),
40
+ ...(dlq !== undefined && { dlq }),
41
+ ...(event !== undefined && { event }),
42
+ ...(fifo !== undefined && { fifo }),
43
+ };
44
+ runValidation(() => validateQueueFunction(functionResource));
45
+ return functionResource;
46
+ }
47
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/definers/functions/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyE,qBAAqB,EAAC,MAAM,gBAAgB,CAAA;AAC5H,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,mBAAmB,CAAC,cAA4C;IAC9E,MAAM,EAAC,WAAW,GAAG,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,GAAG,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAC,GAAG,cAAc,CAAA;IAE/F,MAAM,gBAAgB,GAAmC;QACvD,GAAG,cAAc,CAAC,cAAc,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;QACzD,IAAI,EAAE,uBAAuB;QAC7B,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI,EAAC,WAAW,EAAC,CAAC;QAC/C,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAC,QAAQ,EAAC,CAAC;QACzC,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI,EAAC,WAAW,EAAC,CAAC;QAC/C,GAAG,CAAC,GAAG,KAAK,SAAS,IAAI,EAAC,GAAG,EAAC,CAAC;QAC/B,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAC,KAAK,EAAC,CAAC;QACnC,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,EAAC,IAAI,EAAC,CAAC;KAClC,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAE5D,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { type BlueprintScheduledFunctionConfig, type BlueprintScheduledFunctionResource } from '../../index.js';
2
+ /**
3
+ * Defines a function that is triggered on a schedule.
4
+ * Supports cron expressions or natural language schedules.
5
+ *
6
+ * @remarks
7
+ * Using a cron expression:
8
+ * ```ts
9
+ * defineScheduledFunction({
10
+ * name: 'daily-cleanup',
11
+ * event: {expression: '0 9 * * *'},
12
+ * })
13
+ * ```
14
+ *
15
+ * Using explicit cron fields:
16
+ * ```ts
17
+ * defineScheduledFunction({
18
+ * name: 'daily-cleanup',
19
+ * event: {minute: '0', hour: '9', dayOfMonth: '*', month: '*', dayOfWeek: '*'},
20
+ * })
21
+ * ```
22
+ *
23
+ * The `event.expression` field accepts standard cron expressions or natural language:
24
+ * `'every 15 minutes'`, `'weekdays at 8am'`, `'fridays in the evening'`,
25
+ * `'mon, wed, fri at 9am'`, `'first of the month at noon'`
26
+ *
27
+ * ```ts
28
+ * defineScheduledFunction({
29
+ * name: 'daily-cleanup',
30
+ * event: {expression: 'every day at 9am'},
31
+ * })
32
+ * ```
33
+ * @public
34
+ * @alpha Deploying Scheduled Functions via Blueprints is experimental. This feature is not available publicly yet.
35
+ * @hidden
36
+ * @category Definers
37
+ * @expandType BlueprintScheduledFunctionConfig
38
+ * @param functionConfig The configuration for the scheduled function
39
+ * @returns The validated scheduled function resource
40
+ */
41
+ export declare function defineScheduledFunction(functionConfig: BlueprintScheduledFunctionConfig): BlueprintScheduledFunctionResource;
42
+ /**
43
+ * @deprecated Define scheduled functions using `defineScheduledFunction` instead
44
+ * @hidden
45
+ */
46
+ export declare function defineScheduleFunction(functionConfig: BlueprintScheduledFunctionConfig): BlueprintScheduledFunctionResource;
@@ -0,0 +1,91 @@
1
+ import { validateScheduledFunction, } from '../../index.js';
2
+ import { parseScheduledExpression } from '../../utils/schedule-parser.js';
3
+ import { runValidation } from '../../utils/validation.js';
4
+ import { defineFunction } from './index.js';
5
+ const SCHEDULED_EVENT_KEYS = new Set(['minute', 'hour', 'dayOfWeek', 'month', 'dayOfMonth', 'expression']);
6
+ /**
7
+ * Defines a function that is triggered on a schedule.
8
+ * Supports cron expressions or natural language schedules.
9
+ *
10
+ * @remarks
11
+ * Using a cron expression:
12
+ * ```ts
13
+ * defineScheduledFunction({
14
+ * name: 'daily-cleanup',
15
+ * event: {expression: '0 9 * * *'},
16
+ * })
17
+ * ```
18
+ *
19
+ * Using explicit cron fields:
20
+ * ```ts
21
+ * defineScheduledFunction({
22
+ * name: 'daily-cleanup',
23
+ * event: {minute: '0', hour: '9', dayOfMonth: '*', month: '*', dayOfWeek: '*'},
24
+ * })
25
+ * ```
26
+ *
27
+ * The `event.expression` field accepts standard cron expressions or natural language:
28
+ * `'every 15 minutes'`, `'weekdays at 8am'`, `'fridays in the evening'`,
29
+ * `'mon, wed, fri at 9am'`, `'first of the month at noon'`
30
+ *
31
+ * ```ts
32
+ * defineScheduledFunction({
33
+ * name: 'daily-cleanup',
34
+ * event: {expression: 'every day at 9am'},
35
+ * })
36
+ * ```
37
+ * @public
38
+ * @alpha Deploying Scheduled Functions via Blueprints is experimental. This feature is not available publicly yet.
39
+ * @hidden
40
+ * @category Definers
41
+ * @expandType BlueprintScheduledFunctionConfig
42
+ * @param functionConfig The configuration for the scheduled function
43
+ * @returns The validated scheduled function resource
44
+ */
45
+ export function defineScheduledFunction(functionConfig) {
46
+ const { event, timezone } = functionConfig;
47
+ const functionResource = {
48
+ ...defineFunction(functionConfig, { skipValidation: true, scopeType: 'organization' }),
49
+ type: 'sanity.function.cron',
50
+ event: buildScheduledFunctionEvent(event),
51
+ };
52
+ if (timezone)
53
+ functionResource.timezone = timezone;
54
+ // Always normalize to explicit fields (minute, hour, dayOfWeek, month, dayOfMonth)
55
+ if ('expression' in functionResource.event && typeof functionResource.event.expression === 'string') {
56
+ const cron = parseScheduledExpression(functionResource.event.expression);
57
+ functionResource.event = cronStringToExplicitEvent(cron);
58
+ }
59
+ runValidation(() => validateScheduledFunction(functionResource));
60
+ return functionResource;
61
+ }
62
+ /**
63
+ * @deprecated Define scheduled functions using `defineScheduledFunction` instead
64
+ * @hidden
65
+ */
66
+ export function defineScheduleFunction(functionConfig) {
67
+ return defineScheduledFunction(functionConfig);
68
+ }
69
+ /**
70
+ * Builds a scheduled function event configuration.
71
+ * Filters out non-event properties. Does not parse expressions.
72
+ * @param event Scheduled function event configuration
73
+ * @returns Cleaned scheduled function event configuration
74
+ */
75
+ function buildScheduledFunctionEvent(event) {
76
+ return Object.fromEntries(Object.entries(event).filter(([key]) => SCHEDULED_EVENT_KEYS.has(key)));
77
+ }
78
+ /**
79
+ * Converts a cron expression string (minute hour dayOfMonth month dayOfWeek) to explicit event fields.
80
+ * @param cron Cron string with five space-separated fields
81
+ * @returns Explicit scheduled event with minute, hour, dayOfMonth, month, dayOfWeek
82
+ */
83
+ function cronStringToExplicitEvent(cron) {
84
+ const parts = cron.trim().split(/\s+/);
85
+ if (parts.length !== 5) {
86
+ throw new Error(`Invalid cron string: expected 5 fields, got ${parts.length}`);
87
+ }
88
+ const [minute, hour, dayOfMonth, month, dayOfWeek] = parts;
89
+ return { minute, hour, dayOfMonth, month, dayOfWeek };
90
+ }
91
+ //# sourceMappingURL=scheduled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduled.js","sourceRoot":"","sources":["../../../src/definers/functions/scheduled.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,wBAAwB,EAAC,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAKzC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA;AAErI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,uBAAuB,CAAC,cAAgD;IACtF,MAAM,EAAC,KAAK,EAAE,QAAQ,EAAC,GAAG,cAAc,CAAA;IAExC,MAAM,gBAAgB,GAAuC;QAC3D,GAAG,cAAc,CAAC,cAAc,EAAE,EAAC,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,EAAC,CAAC;QACpF,IAAI,EAAE,sBAAsB;QAC5B,KAAK,EAAE,2BAA2B,CAAC,KAAK,CAAC;KAC1C,CAAA;IAED,IAAI,QAAQ;QAAE,gBAAgB,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAElD,mFAAmF;IACnF,IAAI,YAAY,IAAI,gBAAgB,CAAC,KAAK,IAAI,OAAO,gBAAgB,CAAC,KAAK,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QACpG,MAAM,IAAI,GAAG,wBAAwB,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QACxE,gBAAgB,CAAC,KAAK,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAA;IAC1D,CAAC;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,yBAAyB,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAEhE,OAAO,gBAAgB,CAAA;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,cAAgD;IACrF,OAAO,uBAAuB,CAAC,cAAc,CAAC,CAAA;AAChD,CAAC;AAED;;;;;GAKG;AACH,SAAS,2BAA2B,CAAC,KAA4C;IAC/E,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAgC,CAAC,CAAC,CACzD,CAAA;AAC9C,CAAC;AAED;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACtC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,+CAA+C,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,KAAK,CAAA;IAC1D,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAC,CAAA;AACrD,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type BlueprintSyncTagInvalidateFunctionConfig, type BlueprintSyncTagInvalidateFunctionResource } from '../../index.js';
2
+ /**
3
+ * Defines a function that is triggered on a sync tag invalidate event.
4
+ *
5
+ * @remarks
6
+ * Using implicit event scoping to all datasets in the function project:
7
+ * ```ts
8
+ * defineSyncTagInvalidateFunction({
9
+ * name: 'bustin-caches',
10
+ * })
11
+ * ```
12
+ *
13
+ * Using explicit event scoping to a particular dataset in the function project:
14
+ * ```ts
15
+ * defineSyncTagInvalidateFunction({
16
+ * name: 'bustin-caches',
17
+ * event: {
18
+ * resource: {
19
+ * type: 'dataset',
20
+ * id: 'myProj.myDataset',
21
+ * },
22
+ * },
23
+ * })
24
+ * ```
25
+ * @public
26
+ * @category Definers
27
+ * @expandType BlueprintSyncTagInvalidateFunctionConfig
28
+ * @param functionConfig The configuration for the sync tag invalidate function
29
+ * @returns The validated sync tag invalidate function resource
30
+ */
31
+ export declare function defineSyncTagInvalidateFunction(functionConfig: BlueprintSyncTagInvalidateFunctionConfig): BlueprintSyncTagInvalidateFunctionResource;