@klnap/cache-invalidation 0.0.0-stage → 0.1.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.
Files changed (143) hide show
  1. package/CHANGELOG.md +145 -0
  2. package/LICENSE +21 -0
  3. package/README.md +176 -2
  4. package/dist/consumers/next/compile-tag-template.d.ts +16 -0
  5. package/dist/consumers/next/compile-tag-template.js +83 -0
  6. package/dist/consumers/next/consumer-types.d.ts +98 -0
  7. package/dist/consumers/next/consumer-types.js +3 -0
  8. package/dist/consumers/next/define-cache.d.ts +4 -0
  9. package/dist/consumers/next/define-cache.js +281 -0
  10. package/dist/consumers/next/host-types.d.ts +44 -0
  11. package/dist/consumers/next/host-types.js +3 -0
  12. package/dist/consumers/next/index.d.ts +5 -0
  13. package/dist/consumers/next/index.js +2 -0
  14. package/dist/consumers/next/param-values.d.ts +8 -0
  15. package/dist/consumers/next/param-values.js +23 -0
  16. package/dist/consumers/next/profile.d.ts +2 -0
  17. package/dist/consumers/next/profile.js +18 -0
  18. package/dist/consumers/next/registry-builders.d.ts +3 -0
  19. package/dist/consumers/next/registry-builders.js +155 -0
  20. package/dist/consumers/next/revalidation-handler.d.ts +6 -0
  21. package/dist/consumers/next/revalidation-handler.js +2 -0
  22. package/dist/consumers/next/runtime.d.ts +5 -0
  23. package/dist/consumers/next/runtime.js +560 -0
  24. package/dist/core/cloudevents.d.ts +27 -0
  25. package/dist/core/cloudevents.js +172 -0
  26. package/dist/core/dispatch-outcome.d.ts +4 -0
  27. package/dist/core/dispatch-outcome.js +17 -0
  28. package/dist/core/errors.d.ts +16 -0
  29. package/dist/core/errors.js +28 -0
  30. package/dist/core/event-limits.d.ts +15 -0
  31. package/dist/core/event-limits.js +20 -0
  32. package/dist/core/event-selector.d.ts +9 -0
  33. package/dist/core/event-selector.js +5 -0
  34. package/dist/core/index.d.ts +10 -0
  35. package/dist/core/index.js +6 -0
  36. package/dist/core/resource-changed-schema.d.ts +35 -0
  37. package/dist/core/resource-changed-schema.js +12 -0
  38. package/dist/core/standard-schema.d.ts +2 -0
  39. package/dist/core/standard-schema.js +7 -0
  40. package/dist/core/types.d.ts +35 -0
  41. package/dist/core/types.js +1 -0
  42. package/dist/core/url-segment.d.ts +2 -0
  43. package/dist/core/url-segment.js +17 -0
  44. package/dist/dispatchers/http/index.d.ts +20 -0
  45. package/dist/dispatchers/http/index.js +274 -0
  46. package/dist/dispatchers/http/targets.d.ts +14 -0
  47. package/dist/dispatchers/http/targets.js +26 -0
  48. package/dist/dispatchers/index.d.ts +1 -0
  49. package/dist/dispatchers/index.js +1 -0
  50. package/dist/producers/payload/exclude-fields.d.ts +19 -0
  51. package/dist/producers/payload/exclude-fields.js +75 -0
  52. package/dist/producers/payload/index.d.ts +4 -0
  53. package/dist/producers/payload/index.js +3 -0
  54. package/dist/producers/payload/lifecycle/deferred.d.ts +55 -0
  55. package/dist/producers/payload/lifecycle/deferred.js +111 -0
  56. package/dist/producers/payload/lifecycle/dispatch.d.ts +18 -0
  57. package/dist/producers/payload/lifecycle/dispatch.js +21 -0
  58. package/dist/producers/payload/lifecycle/doc-content.d.ts +8 -0
  59. package/dist/producers/payload/lifecycle/doc-content.js +88 -0
  60. package/dist/producers/payload/lifecycle/draft-status.d.ts +6 -0
  61. package/dist/producers/payload/lifecycle/draft-status.js +15 -0
  62. package/dist/producers/payload/lifecycle/helpers.d.ts +13 -0
  63. package/dist/producers/payload/lifecycle/helpers.js +12 -0
  64. package/dist/producers/payload/lifecycle/identifier-field.d.ts +8 -0
  65. package/dist/producers/payload/lifecycle/identifier-field.js +48 -0
  66. package/dist/producers/payload/lifecycle/identifiers.d.ts +4 -0
  67. package/dist/producers/payload/lifecycle/identifiers.js +5 -0
  68. package/dist/producers/payload/lifecycle/locale-published.d.ts +7 -0
  69. package/dist/producers/payload/lifecycle/locale-published.js +19 -0
  70. package/dist/producers/payload/lifecycle/locale.d.ts +24 -0
  71. package/dist/producers/payload/lifecycle/locale.js +44 -0
  72. package/dist/producers/payload/lifecycle/log.d.ts +31 -0
  73. package/dist/producers/payload/lifecycle/log.js +67 -0
  74. package/dist/producers/payload/lifecycle/media-equality.d.ts +4 -0
  75. package/dist/producers/payload/lifecycle/media-equality.js +36 -0
  76. package/dist/producers/payload/lifecycle/operation.d.ts +2 -0
  77. package/dist/producers/payload/lifecycle/operation.js +7 -0
  78. package/dist/producers/payload/lifecycle/orderable-hooks.d.ts +21 -0
  79. package/dist/producers/payload/lifecycle/orderable-hooks.js +26 -0
  80. package/dist/producers/payload/lifecycle/orderable-neighbors.d.ts +21 -0
  81. package/dist/producers/payload/lifecycle/orderable-neighbors.js +151 -0
  82. package/dist/producers/payload/lifecycle/public-snapshots.d.ts +16 -0
  83. package/dist/producers/payload/lifecycle/public-snapshots.js +173 -0
  84. package/dist/producers/payload/lifecycle/revalidate.d.ts +16 -0
  85. package/dist/producers/payload/lifecycle/revalidate.js +162 -0
  86. package/dist/producers/payload/lifecycle/skip-rules.d.ts +19 -0
  87. package/dist/producers/payload/lifecycle/skip-rules.js +57 -0
  88. package/dist/producers/payload/lifecycle/types.d.ts +32 -0
  89. package/dist/producers/payload/lifecycle/types.js +1 -0
  90. package/dist/producers/payload/media/media-references.d.ts +31 -0
  91. package/dist/producers/payload/media/media-references.js +127 -0
  92. package/dist/producers/payload/media/resolve-media-affected-locales.d.ts +22 -0
  93. package/dist/producers/payload/media/resolve-media-affected-locales.js +70 -0
  94. package/dist/producers/payload/media/resolve-media-dependents.d.ts +39 -0
  95. package/dist/producers/payload/media/resolve-media-dependents.js +157 -0
  96. package/dist/producers/payload/media/resolve-media-slug.d.ts +7 -0
  97. package/dist/producers/payload/media/resolve-media-slug.js +17 -0
  98. package/dist/producers/payload/media/revalidate-media-dependents.d.ts +14 -0
  99. package/dist/producers/payload/media/revalidate-media-dependents.js +222 -0
  100. package/dist/producers/payload/plugin.d.ts +36 -0
  101. package/dist/producers/payload/plugin.js +235 -0
  102. package/dist/producers/payload/publish-all/context.d.ts +2 -0
  103. package/dist/producers/payload/publish-all/context.js +2 -0
  104. package/dist/producers/payload/publish-all/edited-locale.d.ts +5 -0
  105. package/dist/producers/payload/publish-all/edited-locale.js +5 -0
  106. package/dist/producers/payload/publish-all/index.d.ts +3 -0
  107. package/dist/producers/payload/publish-all/index.js +3 -0
  108. package/dist/producers/payload/publish-all/localization.d.ts +7 -0
  109. package/dist/producers/payload/publish-all/localization.js +1 -0
  110. package/dist/producers/payload/publish-all/mirror-publish-all-locales-to-req.d.ts +19 -0
  111. package/dist/producers/payload/publish-all/mirror-publish-all-locales-to-req.js +32 -0
  112. package/dist/producers/payload/publish-all/preserve-locales-on-publish-all.d.ts +2 -0
  113. package/dist/producers/payload/publish-all/preserve-locales-on-publish-all.js +145 -0
  114. package/dist/producers/payload/publish-all/read-localized-scalar.d.ts +2 -0
  115. package/dist/producers/payload/publish-all/read-localized-scalar.js +24 -0
  116. package/dist/producers/payload/publish-all/request-flags.d.ts +13 -0
  117. package/dist/producers/payload/publish-all/request-flags.js +9 -0
  118. package/dist/producers/payload/publish-all/restore-guard.d.ts +2 -0
  119. package/dist/producers/payload/publish-all/restore-guard.js +12 -0
  120. package/dist/producers/payload/publish-all/restore-locales-after-publish-all.d.ts +2 -0
  121. package/dist/producers/payload/publish-all/restore-locales-after-publish-all.js +85 -0
  122. package/dist/producers/payload/revalidation-custom.d.ts +37 -0
  123. package/dist/producers/payload/revalidation-custom.js +54 -0
  124. package/dist/producers/payload/schema.d.ts +3 -0
  125. package/dist/producers/payload/schema.js +23 -0
  126. package/docs/concepts/architecture.md +32 -0
  127. package/docs/concepts/cache-tags.md +97 -0
  128. package/docs/concepts/event-contract.md +38 -0
  129. package/docs/consumers/custom.md +19 -0
  130. package/docs/consumers/next.md +277 -0
  131. package/docs/dispatchers/custom.md +38 -0
  132. package/docs/dispatchers/http.md +66 -0
  133. package/docs/extending.md +26 -0
  134. package/docs/migration/0.3.0-to-0.4.0.md +67 -0
  135. package/docs/migration/0.4.0-to-0.5.0.md +60 -0
  136. package/docs/migration/0.5.x-to-0.0.0.md +143 -0
  137. package/docs/producers/custom.md +63 -0
  138. package/docs/producers/payload-media-dependencies.md +45 -0
  139. package/docs/producers/payload.md +140 -0
  140. package/docs/reliability.md +35 -0
  141. package/docs/security.md +34 -0
  142. package/docs/troubleshooting.md +14 -0
  143. package/package.json +120 -4
@@ -0,0 +1,172 @@
1
+ export const CLOUDEVENTS_JSON = 'application/cloudevents+json';
2
+ export const CLOUDEVENTS_BATCH_JSON = 'application/cloudevents-batch+json';
3
+ const structuredCloudEvent = (event) => {
4
+ if (!(event.data instanceof Uint8Array))
5
+ return event;
6
+ const bytes = Array.from(event.data, (byte) => String.fromCharCode(byte)).join('');
7
+ const { data: _data, ...attributes } = event;
8
+ return { ...attributes, data_base64: btoa(bytes) };
9
+ };
10
+ export const serializeCloudEvent = (event) => JSON.stringify(structuredCloudEvent(event));
11
+ export const serializeCloudEventBatch = (events) => JSON.stringify(events.map(structuredCloudEvent));
12
+ export class CloudEventParseError extends Error {
13
+ constructor(message) {
14
+ super(message);
15
+ this.name = 'CloudEventParseError';
16
+ }
17
+ }
18
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ const isNonEmptyString = (value) => typeof value === 'string' && value.length > 0;
20
+ const isUriReference = (value) => {
21
+ if (!value ||
22
+ [...value].some((character) => {
23
+ const code = character.charCodeAt(0);
24
+ return code <= 0x20 || code === 0x7f;
25
+ }))
26
+ return false;
27
+ try {
28
+ new URL(value, 'https://cloudevents.invalid/');
29
+ return true;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ };
35
+ const isAbsoluteUri = (value) => {
36
+ if (!isUriReference(value))
37
+ return false;
38
+ try {
39
+ const parsed = new URL(value);
40
+ return parsed.protocol.length > 1;
41
+ }
42
+ catch {
43
+ return false;
44
+ }
45
+ };
46
+ const isTimestamp = (value) => {
47
+ const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(Z|([+-])(\d{2}):(\d{2}))$/.exec(value);
48
+ if (!match)
49
+ return false;
50
+ const [, year, month, day, hour, minute, second, , , offsetHour, offsetMinute] = match;
51
+ const y = Number(year);
52
+ const m = Number(month);
53
+ const d = Number(day);
54
+ const h = Number(hour);
55
+ const min = Number(minute);
56
+ const s = Number(second);
57
+ const daysInMonth = new Date(Date.UTC(y, m, 0)).getUTCDate();
58
+ return (m >= 1 &&
59
+ m <= 12 &&
60
+ d >= 1 &&
61
+ d <= daysInMonth &&
62
+ h <= 23 &&
63
+ min <= 59 &&
64
+ s <= 59 &&
65
+ Number(offsetHour ?? 0) <= 23 &&
66
+ Number(offsetMinute ?? 0) <= 59 &&
67
+ Number.isFinite(Date.parse(value)));
68
+ };
69
+ const isJsonContentType = (value) => {
70
+ const mediaType = value.split(';', 1)[0]?.trim().toLowerCase();
71
+ if (!mediaType || !/^application\/(?:json|[a-z0-9!#$&^_.+-]+\+json)$/.test(mediaType)) {
72
+ return false;
73
+ }
74
+ return value
75
+ .split(';')
76
+ .slice(1)
77
+ .every((parameter) => /^\s*[a-z0-9!#$&^_.+-]+\s*=\s*(?:[a-z0-9!#$&^_.+-]+|"[^"]*")\s*$/i.test(parameter));
78
+ };
79
+ const isMediaType = (value) => /^\s*[!#$%&'*+.^_`|~0-9a-z-]+\/[!#$%&'*+.^_`|~0-9a-z-]+(?:\s*;\s*[!#$%&'*+.^_`|~0-9a-z-]+\s*=\s*(?:[!#$%&'*+.^_`|~0-9a-z-]+|"[^"\r\n]*"))*\s*$/i.test(value);
80
+ const isBase64 = (value) => /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);
81
+ const isJsonExtensionValue = (value) => typeof value === 'string' ||
82
+ typeof value === 'boolean' ||
83
+ (typeof value === 'number' && Number.isFinite(value));
84
+ const validateEvent = (value) => {
85
+ if (!isRecord(value))
86
+ throw new CloudEventParseError('CloudEvent must be a JSON object');
87
+ if (value.specversion !== '1.0') {
88
+ throw new CloudEventParseError('CloudEvent specversion must be "1.0"');
89
+ }
90
+ if (!isNonEmptyString(value.id))
91
+ throw new CloudEventParseError('CloudEvent id is required');
92
+ if (!isNonEmptyString(value.source) || !isUriReference(value.source)) {
93
+ throw new CloudEventParseError('CloudEvent source must be a URI-reference');
94
+ }
95
+ if (!isNonEmptyString(value.type))
96
+ throw new CloudEventParseError('CloudEvent type is required');
97
+ if (Object.hasOwn(value, 'data') && typeof value.data === 'undefined') {
98
+ throw new CloudEventParseError('CloudEvent data must be a JSON value');
99
+ }
100
+ if (Object.hasOwn(value, 'data') && Object.hasOwn(value, 'data_base64')) {
101
+ throw new CloudEventParseError('CloudEvent must not contain both data and data_base64');
102
+ }
103
+ if (Object.hasOwn(value, 'data_base64')) {
104
+ if (value.data_base64 !== null &&
105
+ (typeof value.data_base64 !== 'string' || !isBase64(value.data_base64))) {
106
+ throw new CloudEventParseError('CloudEvent data_base64 must be valid base64');
107
+ }
108
+ }
109
+ if (value.subject !== undefined && value.subject !== null && typeof value.subject !== 'string') {
110
+ throw new CloudEventParseError('CloudEvent subject must be a string');
111
+ }
112
+ if (value.time !== undefined && value.time !== null) {
113
+ if (typeof value.time !== 'string' || !isTimestamp(value.time)) {
114
+ throw new CloudEventParseError('CloudEvent time must be an RFC 3339 timestamp');
115
+ }
116
+ }
117
+ if (value.datacontenttype !== undefined &&
118
+ value.datacontenttype !== null &&
119
+ (typeof value.datacontenttype !== 'string' || !isMediaType(value.datacontenttype))) {
120
+ throw new CloudEventParseError('CloudEvent datacontenttype must be a valid media type');
121
+ }
122
+ if (value.dataschema !== undefined &&
123
+ value.dataschema !== null &&
124
+ (typeof value.dataschema !== 'string' || !isAbsoluteUri(value.dataschema))) {
125
+ throw new CloudEventParseError('CloudEvent dataschema must be an absolute URI');
126
+ }
127
+ const standardAttributes = new Set([
128
+ 'specversion',
129
+ 'id',
130
+ 'source',
131
+ 'type',
132
+ 'time',
133
+ 'subject',
134
+ 'datacontenttype',
135
+ 'dataschema',
136
+ 'data',
137
+ 'data_base64',
138
+ ]);
139
+ for (const [name, extensionValue] of Object.entries(value)) {
140
+ if (standardAttributes.has(name))
141
+ continue;
142
+ if (!/^[a-z0-9]{1,20}$/.test(name) || !isJsonExtensionValue(extensionValue)) {
143
+ throw new CloudEventParseError(`CloudEvent extension attribute "${name}" is invalid`);
144
+ }
145
+ }
146
+ if (typeof value.data_base64 === 'string') {
147
+ const binary = atob(value.data_base64);
148
+ const data = Uint8Array.from(binary, (character) => character.charCodeAt(0));
149
+ const event = { ...value };
150
+ delete event.data_base64;
151
+ event.data = data;
152
+ return event;
153
+ }
154
+ return value;
155
+ };
156
+ const normalizeMediaType = (contentType) => contentType.split(';', 1)[0]?.trim().toLowerCase() ?? '';
157
+ export const parseCloudEvents = (value, contentType) => {
158
+ const mediaType = normalizeMediaType(contentType);
159
+ if (mediaType === CLOUDEVENTS_JSON) {
160
+ if (!isJsonContentType(contentType) || Array.isArray(value)) {
161
+ throw new CloudEventParseError('Expected one CloudEvent JSON object');
162
+ }
163
+ return [validateEvent(value)];
164
+ }
165
+ if (mediaType === CLOUDEVENTS_BATCH_JSON) {
166
+ if (!isJsonContentType(contentType) || !Array.isArray(value)) {
167
+ throw new CloudEventParseError('Expected a CloudEvents JSON batch');
168
+ }
169
+ return value.map(validateEvent);
170
+ }
171
+ throw new CloudEventParseError('Unsupported CloudEvents content type');
172
+ };
@@ -0,0 +1,4 @@
1
+ import type { DispatchError, DispatchOutcome, TargetDispatchResult } from './types.js';
2
+ export declare const createDispatchError: (code: string, message: string) => DispatchError;
3
+ /** Merge per-target-chunk outcomes into one dispatcher result. */
4
+ export declare const aggregateDispatchOutcomes: (results: readonly TargetDispatchResult[]) => DispatchOutcome;
@@ -0,0 +1,17 @@
1
+ export const createDispatchError = (code, message) => ({
2
+ code,
3
+ message,
4
+ });
5
+ /** Merge per-target-chunk outcomes into one dispatcher result. */
6
+ export const aggregateDispatchOutcomes = (results) => {
7
+ if (results.length === 0 || results.every(({ status }) => status === 'accepted')) {
8
+ return { status: 'accepted', results };
9
+ }
10
+ if (results.some(({ status }) => status === 'accepted'))
11
+ return { status: 'partial', results };
12
+ if (results.some(({ status }) => status === 'unknown'))
13
+ return { status: 'unknown', results };
14
+ if (results.every(({ status }) => status === 'rejected'))
15
+ return { status: 'rejected', results };
16
+ return { status: 'failed', results };
17
+ };
@@ -0,0 +1,16 @@
1
+ export declare class CacheRequestError extends Error {
2
+ readonly code = "CACHE_REQUEST_ERROR";
3
+ constructor(message: string);
4
+ }
5
+ export declare class CacheSourceError extends Error {
6
+ readonly code = "CACHE_SOURCE_ERROR";
7
+ constructor(message: string);
8
+ }
9
+ export declare class CacheSchemaError extends Error {
10
+ readonly code = "CACHE_SCHEMA_ERROR";
11
+ constructor(message: string);
12
+ }
13
+ export declare class CacheConfigurationError extends Error {
14
+ readonly code = "CACHE_CONFIGURATION_ERROR";
15
+ constructor(message: string);
16
+ }
@@ -0,0 +1,28 @@
1
+ export class CacheRequestError extends Error {
2
+ code = 'CACHE_REQUEST_ERROR';
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = 'CacheRequestError';
6
+ }
7
+ }
8
+ export class CacheSourceError extends Error {
9
+ code = 'CACHE_SOURCE_ERROR';
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = 'CacheSourceError';
13
+ }
14
+ }
15
+ export class CacheSchemaError extends Error {
16
+ code = 'CACHE_SCHEMA_ERROR';
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'CacheSchemaError';
20
+ }
21
+ }
22
+ export class CacheConfigurationError extends Error {
23
+ code = 'CACHE_CONFIGURATION_ERROR';
24
+ constructor(message) {
25
+ super(message);
26
+ this.name = 'CacheConfigurationError';
27
+ }
28
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Maximum number of items in one revalidation event. Consumers reject larger events with HTTP 400,
3
+ * so the producer splits larger change sets into several events of at most this many items.
4
+ * The consumer default uses the same value; a host that lowers its consumer limit must also lower
5
+ * this producer limit, or chunks will be rejected.
6
+ */
7
+ export declare const DEFAULT_MAX_EVENT_ITEMS = 100;
8
+ /** Hardest upper bound for items per event. Configuration above it is rejected at startup. */
9
+ export declare const MAX_EVENT_ITEMS_CEILING = 1000;
10
+ /** Request body size the consumer reads by default. */
11
+ export declare const DEFAULT_MAX_BODY_BYTES: number;
12
+ /** Hardest upper bound for the request body size. Configuration above it is rejected at startup. */
13
+ export declare const MAX_BODY_BYTES_CEILING: number;
14
+ /** Returns `value` when it is an integer from 1 to `ceiling`; otherwise throws a configuration error. */
15
+ export declare const assertLimit: (name: string, value: number, ceiling: number) => number;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Maximum number of items in one revalidation event. Consumers reject larger events with HTTP 400,
3
+ * so the producer splits larger change sets into several events of at most this many items.
4
+ * The consumer default uses the same value; a host that lowers its consumer limit must also lower
5
+ * this producer limit, or chunks will be rejected.
6
+ */
7
+ export const DEFAULT_MAX_EVENT_ITEMS = 100;
8
+ /** Hardest upper bound for items per event. Configuration above it is rejected at startup. */
9
+ export const MAX_EVENT_ITEMS_CEILING = 1000;
10
+ /** Request body size the consumer reads by default. */
11
+ export const DEFAULT_MAX_BODY_BYTES = 256 * 1024;
12
+ /** Hardest upper bound for the request body size. Configuration above it is rejected at startup. */
13
+ export const MAX_BODY_BYTES_CEILING = 16 * 1024 * 1024;
14
+ /** Returns `value` when it is an integer from 1 to `ceiling`; otherwise throws a configuration error. */
15
+ export const assertLimit = (name, value, ceiling) => {
16
+ if (!Number.isInteger(value) || value < 1 || value > ceiling) {
17
+ throw new RangeError(`${name} must be an integer from 1 to ${ceiling}; got ${value}`);
18
+ }
19
+ return value;
20
+ };
@@ -0,0 +1,9 @@
1
+ import type { CloudEvent } from './cloudevents.js';
2
+ type Selectable<T extends string> = T | readonly T[];
3
+ /** Filters CloudEvents by protocol attributes without interpreting domain data. */
4
+ export type EventSelector = {
5
+ source?: Selectable<string>;
6
+ type?: Selectable<string>;
7
+ };
8
+ export declare const matchesEventSelector: (event: CloudEvent, selector: EventSelector) => boolean;
9
+ export {};
@@ -0,0 +1,5 @@
1
+ const includes = (expected, actual) => typeof expected === 'string'
2
+ ? expected === actual
3
+ : expected.some((candidate) => candidate === actual);
4
+ export const matchesEventSelector = (event, selector) => (selector.source === undefined || includes(selector.source, event.source)) &&
5
+ (selector.type === undefined || includes(selector.type, event.type));
@@ -0,0 +1,10 @@
1
+ export type { CloudEvent } from './cloudevents.js';
2
+ export { CLOUDEVENTS_BATCH_JSON, CLOUDEVENTS_JSON, CloudEventParseError, parseCloudEvents, serializeCloudEvent, serializeCloudEventBatch, } from './cloudevents.js';
3
+ export { aggregateDispatchOutcomes, createDispatchError } from './dispatch-outcome.js';
4
+ export { CacheConfigurationError, CacheRequestError, CacheSchemaError, CacheSourceError, } from './errors.js';
5
+ export type { EventSelector } from './event-selector.js';
6
+ export { matchesEventSelector } from './event-selector.js';
7
+ export type { ResourceChangeV1, ResourceChangeV1Data } from './resource-changed-schema.js';
8
+ export { resourceChangeV1DataSchema, resourceChangeV1DataSchemaUri, } from './resource-changed-schema.js';
9
+ export { validateStandardSchema } from './standard-schema.js';
10
+ export type { DeliveryStatus, DispatchError, Dispatcher, DispatchInput, DispatchOutcome, Logger, TargetDispatchResult, } from './types.js';
@@ -0,0 +1,6 @@
1
+ export { CLOUDEVENTS_BATCH_JSON, CLOUDEVENTS_JSON, CloudEventParseError, parseCloudEvents, serializeCloudEvent, serializeCloudEventBatch, } from './cloudevents.js';
2
+ export { aggregateDispatchOutcomes, createDispatchError } from './dispatch-outcome.js';
3
+ export { CacheConfigurationError, CacheRequestError, CacheSchemaError, CacheSourceError, } from './errors.js';
4
+ export { matchesEventSelector } from './event-selector.js';
5
+ export { resourceChangeV1DataSchema, resourceChangeV1DataSchemaUri, } from './resource-changed-schema.js';
6
+ export { validateStandardSchema } from './standard-schema.js';
@@ -0,0 +1,35 @@
1
+ import * as v from 'valibot';
2
+ export declare const resourceChangeV1DataSchemaUri: 'urn:klnap:revalidation:resource-change:v1';
3
+ export type ResourceChangeV1<T = Record<string, unknown>> = {
4
+ operation: string;
5
+ before: T | null;
6
+ after: T | null;
7
+ affected?: Array<{
8
+ type: string;
9
+ data: Record<string, unknown>;
10
+ }>;
11
+ };
12
+ export declare const resourceChangeV1DataSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
13
+ readonly operation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
14
+ readonly before: v.NullableSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
15
+ readonly after: v.NullableSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
16
+ readonly affected: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
17
+ readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
18
+ readonly data: v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>;
19
+ }, undefined>, undefined>, undefined>;
20
+ }, undefined>, v.CheckAction<{
21
+ operation: string;
22
+ before: {
23
+ [x: string]: unknown;
24
+ } | null;
25
+ after: {
26
+ [x: string]: unknown;
27
+ } | null;
28
+ affected?: {
29
+ type: string;
30
+ data: {
31
+ [x: string]: unknown;
32
+ };
33
+ }[] | undefined;
34
+ }, "Resource Change V1 must include a before or after snapshot">]>;
35
+ export type ResourceChangeV1Data = v.InferOutput<typeof resourceChangeV1DataSchema>;
@@ -0,0 +1,12 @@
1
+ import * as v from 'valibot';
2
+ export const resourceChangeV1DataSchemaUri = 'urn:klnap:revalidation:resource-change:v1';
3
+ const resourceSnapshotSchema = v.record(v.string(), v.unknown());
4
+ export const resourceChangeV1DataSchema = v.pipe(v.object({
5
+ operation: v.pipe(v.string(), v.minLength(1)),
6
+ before: v.nullable(resourceSnapshotSchema),
7
+ after: v.nullable(resourceSnapshotSchema),
8
+ affected: v.optional(v.array(v.object({
9
+ type: v.pipe(v.string(), v.minLength(1)),
10
+ data: v.record(v.string(), v.unknown()),
11
+ }))),
12
+ }), v.check((value) => value.before !== null || value.after !== null, 'Resource Change V1 must include a before or after snapshot'));
@@ -0,0 +1,2 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ export declare const validateStandardSchema: <TOutput>(schema: StandardSchemaV1<unknown, TOutput>, value: unknown) => Promise<TOutput>;
@@ -0,0 +1,7 @@
1
+ import { CacheSchemaError } from './errors.js';
2
+ export const validateStandardSchema = async (schema, value) => {
3
+ const result = await schema['~standard'].validate(value);
4
+ if (result.issues)
5
+ throw new CacheSchemaError('Schema validation failed');
6
+ return result.value;
7
+ };
@@ -0,0 +1,35 @@
1
+ import type { CloudEvent } from './cloudevents.js';
2
+ export type DispatchError = {
3
+ code: string;
4
+ message: string;
5
+ };
6
+ export type DeliveryStatus = 'accepted' | 'rejected' | 'failed' | 'unknown';
7
+ export type TargetDispatchResult = {
8
+ target: string;
9
+ deliveryId: string;
10
+ status: DeliveryStatus;
11
+ attempts: number;
12
+ error?: DispatchError;
13
+ };
14
+ export type DispatchOutcome = {
15
+ status: 'accepted';
16
+ results: readonly TargetDispatchResult[];
17
+ } | {
18
+ status: 'partial';
19
+ results: readonly TargetDispatchResult[];
20
+ } | {
21
+ status: 'rejected' | 'failed' | 'unknown';
22
+ results: readonly TargetDispatchResult[];
23
+ };
24
+ export type DispatchInput = {
25
+ events: readonly CloudEvent[];
26
+ };
27
+ export type Dispatcher = {
28
+ dispatch(input: DispatchInput): Promise<DispatchOutcome>;
29
+ };
30
+ export type Logger = {
31
+ debug?: (entry: Record<string, unknown>, message: string) => void;
32
+ info?: (entry: Record<string, unknown>, message: string) => void;
33
+ warn?: (entry: Record<string, unknown>, message: string) => void;
34
+ error?: (entry: Record<string, unknown>, message: string) => void;
35
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ /** Why a value is unsafe as a single URL path segment, or `undefined` when it is safe. */
2
+ export declare const urlSegmentProblem: (value: string) => string | undefined;
@@ -0,0 +1,17 @@
1
+ /** Why a value is unsafe as a single URL path segment, or `undefined` when it is safe. */
2
+ export const urlSegmentProblem = (value) => {
3
+ if (value.includes('?') || value.includes('#'))
4
+ return 'a query or fragment delimiter';
5
+ let decoded;
6
+ try {
7
+ decoded = decodeURIComponent(value);
8
+ }
9
+ catch {
10
+ return 'malformed percent encoding';
11
+ }
12
+ if (decoded === '.' || decoded === '..')
13
+ return 'a dot segment';
14
+ if (/[/\\\p{Cc}]/u.test(decoded))
15
+ return 'a path separator or control character';
16
+ return undefined;
17
+ };
@@ -0,0 +1,20 @@
1
+ import { type Dispatcher, type DispatchInput, type DispatchOutcome } from '../../core/index.js';
2
+ import { type TargetConfig } from './targets.js';
3
+ export type { CacheInvalidationTarget, TargetConfig } from './targets.js';
4
+ export type HttpDispatchInput = DispatchInput & {
5
+ targets?: readonly string[];
6
+ };
7
+ export type HttpDispatcher = Omit<Dispatcher, 'dispatch'> & {
8
+ dispatch(input: HttpDispatchInput): Promise<DispatchOutcome>;
9
+ };
10
+ export type HttpDispatcherConfig = {
11
+ targets: TargetConfig;
12
+ timeoutMs?: number;
13
+ deadlineMs?: number;
14
+ retries?: number;
15
+ retryDelayMs?: number;
16
+ allowInsecure?: boolean;
17
+ maxEventItems?: number;
18
+ maxBodyBytes?: number;
19
+ };
20
+ export declare const http: (config: HttpDispatcherConfig) => HttpDispatcher;