@hypequery/protocol 0.8.0 → 0.10.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/README.md CHANGED
@@ -29,7 +29,7 @@ authentication or tenancy, or contain CLI, HTTP, UI, and Cloud operations.
29
29
 
30
30
  Self-hosted Serve continues to run project source directly. Deployment bundles
31
31
  are required only by Cloud deployment and may be generated ephemerally for
32
- Studio compatibility and security diagnostics.
32
+ local compatibility and security diagnostics.
33
33
 
34
34
  ## Public API
35
35
 
@@ -3,5 +3,5 @@ export { PROTOCOL_DEPLOYMENT_BUNDLE_IDENTITY_DOMAIN, encodeProtocolDeploymentBun
3
3
  export type { PreparedProtocolDeploymentBundleManifest } from './codec.js';
4
4
  export { DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS } from './limits.js';
5
5
  export { validateProtocolDeploymentBundleManifest } from './validate.js';
6
- export type { ProtocolDeploymentBundleArtifact, ProtocolDeploymentBundleDeployment, ProtocolDeploymentBundleErrorCode, ProtocolDeploymentBundleFile, ProtocolDeploymentBundleLimits, ProtocolDeploymentBundleManifest, ProtocolDeploymentBundleOptions, } from './types.js';
6
+ export type { ProtocolDeploymentBundleArtifact, ProtocolDeploymentBundleDeployment, ProtocolDeploymentBundleErrorCode, ProtocolDeploymentBundleFile, ProtocolDeploymentBundleLimits, ProtocolDeploymentBundleManifest, ProtocolDeploymentBundleOptions, ProtocolDeploymentBundleSource, ProtocolDeploymentBundleSourceRevision, } from './types.js';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,0CAA0C,EAC1C,sCAAsC,EACtC,8CAA8C,EAC9C,oCAAoC,EACpC,uCAAuC,GACxC,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,wCAAwC,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,wCAAwC,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EACV,gCAAgC,EAChC,kCAAkC,EAClC,iCAAiC,EACjC,4BAA4B,EAC5B,8BAA8B,EAC9B,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundles/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,0CAA0C,EAC1C,sCAAsC,EACtC,8CAA8C,EAC9C,oCAAoC,EACpC,uCAAuC,GACxC,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,wCAAwC,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,wCAAwC,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EACV,gCAAgC,EAChC,kCAAkC,EAClC,iCAAiC,EACjC,4BAA4B,EAC5B,8BAA8B,EAC9B,gCAAgC,EAChC,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,GACvC,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/bundles/limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,+BAA+B,EAChC,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,yCAAyC,EACtD,QAAQ,CAAC,8BAA8B,CAMrC,CAAC;AAEH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,+BAAoC,GAC5C,QAAQ,CAAC,8BAA8B,CAAC,CAe1C"}
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/bundles/limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,+BAA+B,EAChC,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,yCAAyC,EACtD,QAAQ,CAAC,8BAA8B,CASrC,CAAC;AAEH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,+BAAoC,GAC5C,QAAQ,CAAC,8BAA8B,CAAC,CAe1C"}
@@ -1,8 +1,11 @@
1
1
  export const DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS = Object.freeze({
2
2
  maxArtifacts: 100,
3
+ maxSourceFiles: 1_000,
3
4
  maxPathBytes: 1_024,
4
5
  maxDeploymentBytes: 16 * 1_024 * 1_024,
5
6
  maxArtifactBytes: 128 * 1_024 * 1_024,
7
+ maxSourceFileBytes: 2 * 1_024 * 1_024,
8
+ maxSourceBytes: 32 * 1_024 * 1_024,
6
9
  maxTotalBytes: 256 * 1_024 * 1_024,
7
10
  });
8
11
  export function resolveDeploymentBundleLimits(options = {}) {
@@ -9,17 +9,34 @@ export interface ProtocolDeploymentBundleDeployment extends ProtocolDeploymentBu
9
9
  export interface ProtocolDeploymentBundleArtifact extends ProtocolDeploymentBundleFile {
10
10
  readonly runtime: 'node' | 'python';
11
11
  }
12
+ export interface ProtocolDeploymentBundleSourceRevision {
13
+ readonly kind: 'git';
14
+ readonly commit: string;
15
+ readonly dirty: boolean;
16
+ }
17
+ export interface ProtocolDeploymentBundleSource {
18
+ /** Directory within the closed bundle that contains project-relative source files. */
19
+ readonly root: string;
20
+ /** Project-relative API module used to build the deployment. */
21
+ readonly entrypoint: string;
22
+ readonly files: readonly ProtocolDeploymentBundleFile[];
23
+ readonly revision?: ProtocolDeploymentBundleSourceRevision;
24
+ }
12
25
  export interface ProtocolDeploymentBundleManifest {
13
26
  readonly kind: 'hypequery-deployment-bundle';
14
27
  readonly version: 1;
15
28
  readonly deployment: ProtocolDeploymentBundleDeployment;
16
29
  readonly artifacts: readonly ProtocolDeploymentBundleArtifact[];
30
+ readonly source?: ProtocolDeploymentBundleSource;
17
31
  }
18
32
  export interface ProtocolDeploymentBundleLimits {
19
33
  readonly maxArtifacts: number;
34
+ readonly maxSourceFiles: number;
20
35
  readonly maxPathBytes: number;
21
36
  readonly maxDeploymentBytes: number;
22
37
  readonly maxArtifactBytes: number;
38
+ readonly maxSourceFileBytes: number;
39
+ readonly maxSourceBytes: number;
23
40
  readonly maxTotalBytes: number;
24
41
  }
25
42
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/bundles/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,kCAAmC,SAAQ,4BAA4B;IACtF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gCAAiC,SAAQ,4BAA4B;IACpF,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAC;CACrC;AAED,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,IAAI,EAAE,6BAA6B,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,kCAAkC,CAAC;IACxD,QAAQ,CAAC,SAAS,EAAE,SAAS,gCAAgC,EAAE,CAAC;CACjE;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,+BAA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,CAAC,UAAU,EAAE,kCAAkC,CAAC;IACxD,QAAQ,CAAC,SAAS,EAAE,SAAS,gCAAgC,EAAE,CAAC;IAChE,QAAQ,CAAC,MAAM,CAAC,EAAE,8BAA8B,CAAC;CAClD;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC;CAC3D;AAED,MAAM,MAAM,iCAAiC,GACzC,gBAAgB,GAChB,yBAAyB,GACzB,2BAA2B,GAC3B,yBAAyB,GACzB,wBAAwB,GACxB,6BAA6B,GAC7B,0BAA0B,GAC1B,qBAAqB,GACrB,yBAAyB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/bundles/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAIV,gCAAgC,EAChC,+BAA+B,EAChC,MAAM,YAAY,CAAC;AA4HpB,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,+BAAoC,GAC5C,gCAAgC,CAwClC"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/bundles/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAIV,gCAAgC,EAChC,+BAA+B,EAGhC,MAAM,YAAY,CAAC;AA4NpB,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,+BAAoC,GAC5C,gCAAgC,CA+ClC"}
@@ -2,6 +2,7 @@ import { bundleError } from './errors.js';
2
2
  import { resolveDeploymentBundleLimits } from './limits.js';
3
3
  const textEncoder = new TextEncoder();
4
4
  const SHA256_PATTERN = /^[0-9a-f]{64}$/;
5
+ const GIT_COMMIT_PATTERN = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
5
6
  const PATH_SEGMENT_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
6
7
  const WINDOWS_RESERVED_NAME = /^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i;
7
8
  function requireRecord(input, path) {
@@ -44,8 +45,8 @@ function requireArray(input, path, maxItems) {
44
45
  }
45
46
  return input;
46
47
  }
47
- function exactFields(value, required, path) {
48
- const allowed = new Set(required);
48
+ function exactFields(value, required, path, optional = []) {
49
+ const allowed = new Set([...required, ...optional]);
49
50
  for (const key of Object.keys(value)) {
50
51
  if (!allowed.has(key))
51
52
  bundleError('HQ_BUNDLE_UNKNOWN_FIELD', `${path}.${key}`);
@@ -65,8 +66,8 @@ function digest(value, path) {
65
66
  bundleError('HQ_BUNDLE_INVALID_VALUE', path);
66
67
  return value;
67
68
  }
68
- function byteLength(value, path, maximum) {
69
- if (!Number.isSafeInteger(value) || value < 1) {
69
+ function byteLength(value, path, maximum, allowEmpty = false) {
70
+ if (!Number.isSafeInteger(value) || value < (allowEmpty ? 0 : 1)) {
70
71
  bundleError('HQ_BUNDLE_INVALID_VALUE', path);
71
72
  }
72
73
  if (value > maximum)
@@ -112,10 +113,79 @@ function validateArtifact(input, path, limits) {
112
113
  byteLength: byteLength(value.byteLength, `${path}.byteLength`, limits.maxArtifactBytes),
113
114
  });
114
115
  }
116
+ function validateSourceRevision(input, path) {
117
+ const value = requireRecord(input, path);
118
+ exactFields(value, ['kind', 'commit', 'dirty'], path);
119
+ if (value.kind !== 'git') {
120
+ if (typeof value.kind !== 'string')
121
+ bundleError('HQ_BUNDLE_TYPE', `${path}.kind`);
122
+ bundleError('HQ_BUNDLE_INVALID_VALUE', `${path}.kind`);
123
+ }
124
+ if (typeof value.commit !== 'string')
125
+ bundleError('HQ_BUNDLE_TYPE', `${path}.commit`);
126
+ if (!GIT_COMMIT_PATTERN.test(value.commit)) {
127
+ bundleError('HQ_BUNDLE_INVALID_VALUE', `${path}.commit`);
128
+ }
129
+ if (typeof value.dirty !== 'boolean')
130
+ bundleError('HQ_BUNDLE_TYPE', `${path}.dirty`);
131
+ return freezeRecord({
132
+ kind: 'git',
133
+ commit: value.commit,
134
+ dirty: value.dirty,
135
+ });
136
+ }
137
+ function validateSource(input, path, limits) {
138
+ const value = requireRecord(input, path);
139
+ exactFields(value, ['root', 'entrypoint', 'files'], path, ['revision']);
140
+ const root = relativePath(value.root, `${path}.root`, limits.maxPathBytes);
141
+ const entrypoint = relativePath(value.entrypoint, `${path}.entrypoint`, limits.maxPathBytes);
142
+ const files = Object.freeze(requireArray(value.files, `${path}.files`, limits.maxSourceFiles)
143
+ .map((inputFile, index) => {
144
+ const filePath = `${path}.files[${index}]`;
145
+ const file = requireRecord(inputFile, filePath);
146
+ exactFields(file, ['path', 'sha256', 'byteLength'], filePath);
147
+ return freezeRecord({
148
+ path: relativePath(file.path, `${filePath}.path`, limits.maxPathBytes),
149
+ sha256: digest(file.sha256, `${filePath}.sha256`),
150
+ byteLength: byteLength(file.byteLength, `${filePath}.byteLength`, limits.maxSourceFileBytes, true),
151
+ });
152
+ }));
153
+ if (files.length < 1 || !files.some(file => file.path === entrypoint)) {
154
+ bundleError('HQ_BUNDLE_INVALID_REFERENCE', `${path}.entrypoint`);
155
+ }
156
+ const paths = files.map(file => file.path);
157
+ if (new Set(paths).size !== paths.length
158
+ || new Set(paths.map(filePath => filePath.toLowerCase())).size !== paths.length) {
159
+ bundleError('HQ_BUNDLE_INVALID_REFERENCE', `${path}.files`);
160
+ }
161
+ const sortedPaths = [...paths].sort();
162
+ if (paths.some((filePath, index) => filePath !== sortedPaths[index])) {
163
+ bundleError('HQ_BUNDLE_INVALID_VALUE', `${path}.files`);
164
+ }
165
+ const sourceBytes = files.reduce((total, file) => total + file.byteLength, 0);
166
+ if (!Number.isSafeInteger(sourceBytes) || sourceBytes > limits.maxSourceBytes) {
167
+ bundleError('HQ_BUNDLE_TOO_LARGE', path);
168
+ }
169
+ return freezeRecord({
170
+ root,
171
+ entrypoint,
172
+ files,
173
+ ...(value.revision === undefined
174
+ ? {}
175
+ : { revision: validateSourceRevision(value.revision, `${path}.revision`) }),
176
+ });
177
+ }
178
+ function hasTreeCollision(paths) {
179
+ const normalized = new Set(paths.map(bundlePath => bundlePath.toLowerCase()));
180
+ return [...normalized].some((bundlePath) => {
181
+ const segments = bundlePath.split('/');
182
+ return segments.some((_, index) => index > 0 && normalized.has(segments.slice(0, index).join('/')));
183
+ });
184
+ }
115
185
  export function validateProtocolDeploymentBundleManifest(input, options = {}) {
116
186
  const limits = resolveDeploymentBundleLimits(options);
117
187
  const value = requireRecord(input, '$');
118
- exactFields(value, ['kind', 'version', 'deployment', 'artifacts'], '$');
188
+ exactFields(value, ['kind', 'version', 'deployment', 'artifacts'], '$', ['source']);
119
189
  if (value.kind !== 'hypequery-deployment-bundle') {
120
190
  if (typeof value.kind !== 'string')
121
191
  bundleError('HQ_BUNDLE_TYPE', '$.kind');
@@ -129,10 +199,15 @@ export function validateProtocolDeploymentBundleManifest(input, options = {}) {
129
199
  const deployment = validateDeployment(value.deployment, '$.deployment', limits);
130
200
  const artifacts = Object.freeze(requireArray(value.artifacts, '$.artifacts', limits.maxArtifacts)
131
201
  .map((artifact, index) => validateArtifact(artifact, `$.artifacts[${index}]`, limits)));
132
- const paths = [deployment.path, ...artifacts.map(artifact => artifact.path)];
202
+ const source = value.source === undefined
203
+ ? undefined
204
+ : validateSource(value.source, '$.source', limits);
205
+ const sourcePaths = source?.files.map(file => `${source.root}/${file.path}`) ?? [];
206
+ const paths = [deployment.path, ...artifacts.map(artifact => artifact.path), ...sourcePaths];
133
207
  if (new Set(paths).size !== paths.length
134
- || new Set(paths.map(bundlePath => bundlePath.toLowerCase())).size !== paths.length) {
135
- bundleError('HQ_BUNDLE_INVALID_REFERENCE', '$.artifacts');
208
+ || new Set(paths.map(bundlePath => bundlePath.toLowerCase())).size !== paths.length
209
+ || hasTreeCollision(paths)) {
210
+ bundleError('HQ_BUNDLE_INVALID_REFERENCE', '$');
136
211
  }
137
212
  if (new Set(artifacts.map(artifact => artifact.sha256)).size !== artifacts.length) {
138
213
  bundleError('HQ_BUNDLE_INVALID_REFERENCE', '$.artifacts');
@@ -142,7 +217,8 @@ export function validateProtocolDeploymentBundleManifest(input, options = {}) {
142
217
  bundleError('HQ_BUNDLE_INVALID_VALUE', '$.artifacts');
143
218
  }
144
219
  const totalBytes = deployment.byteLength
145
- + artifacts.reduce((total, artifact) => total + artifact.byteLength, 0);
220
+ + artifacts.reduce((total, artifact) => total + artifact.byteLength, 0)
221
+ + (source?.files.reduce((total, file) => total + file.byteLength, 0) ?? 0);
146
222
  if (!Number.isSafeInteger(totalBytes) || totalBytes > limits.maxTotalBytes) {
147
223
  bundleError('HQ_BUNDLE_TOO_LARGE', '$');
148
224
  }
@@ -151,5 +227,6 @@ export function validateProtocolDeploymentBundleManifest(input, options = {}) {
151
227
  version: 1,
152
228
  deployment,
153
229
  artifacts,
230
+ ...(source ? { source } : {}),
154
231
  });
155
232
  }
@@ -0,0 +1,14 @@
1
+ import type { ProtocolQueryDiagnosticsErrorCode, ProtocolQueryEventErrorCode } from './types.js';
2
+ export declare class ProtocolQueryEventError extends TypeError {
3
+ readonly code: ProtocolQueryEventErrorCode;
4
+ readonly path: string;
5
+ constructor(code: ProtocolQueryEventErrorCode, path?: string);
6
+ }
7
+ export declare function eventError(code: ProtocolQueryEventErrorCode, path?: string): never;
8
+ export declare class ProtocolQueryDiagnosticsError extends TypeError {
9
+ readonly code: ProtocolQueryDiagnosticsErrorCode;
10
+ readonly path: string;
11
+ constructor(code: ProtocolQueryDiagnosticsErrorCode, path?: string);
12
+ }
13
+ export declare function diagnosticsError(code: ProtocolQueryDiagnosticsErrorCode, path?: string): never;
14
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/events/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iCAAiC,EACjC,2BAA2B,EAC5B,MAAM,YAAY,CAAC;AAEpB,qBAAa,uBAAwB,SAAQ,SAAS;IACpD,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,2BAA2B,EAAE,IAAI,SAAM;CAM1D;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,2BAA2B,EACjC,IAAI,SAAM,GACT,KAAK,CAEP;AAED,qBAAa,6BAA8B,SAAQ,SAAS;IAC1D,QAAQ,CAAC,IAAI,EAAE,iCAAiC,CAAC;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,iCAAiC,EAAE,IAAI,SAAM;CAMhE;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,iCAAiC,EACvC,IAAI,SAAM,GACT,KAAK,CAEP"}
@@ -0,0 +1,26 @@
1
+ export class ProtocolQueryEventError extends TypeError {
2
+ code;
3
+ path;
4
+ constructor(code, path = '$') {
5
+ super(`${code} at ${path}`);
6
+ this.name = 'ProtocolQueryEventError';
7
+ this.code = code;
8
+ this.path = path;
9
+ }
10
+ }
11
+ export function eventError(code, path = '$') {
12
+ throw new ProtocolQueryEventError(code, path);
13
+ }
14
+ export class ProtocolQueryDiagnosticsError extends TypeError {
15
+ code;
16
+ path;
17
+ constructor(code, path = '$') {
18
+ super(`${code} at ${path}`);
19
+ this.name = 'ProtocolQueryDiagnosticsError';
20
+ this.code = code;
21
+ this.path = path;
22
+ }
23
+ }
24
+ export function diagnosticsError(code, path = '$') {
25
+ throw new ProtocolQueryDiagnosticsError(code, path);
26
+ }
@@ -0,0 +1,5 @@
1
+ export { ProtocolQueryDiagnosticsError, ProtocolQueryEventError, } from './errors.js';
2
+ export { DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS } from './limits.js';
3
+ export { validateProtocolQueryDiagnostics, validateProtocolQueryEvent, } from './validate.js';
4
+ export type { ProtocolQueryDiagnostics, ProtocolQueryDiagnosticsErrorCode, ProtocolQueryErrorCategory, ProtocolQueryEvent, ProtocolQueryEventErrorCode, ProtocolQueryEventLimits, ProtocolQueryEventOptions, ProtocolQueryEventOutcome, ProtocolQueryEventTarget, ProtocolQueryOperation, ProtocolQueryTerminalReason, } from './types.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EACL,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,wBAAwB,EACxB,iCAAiC,EACjC,0BAA0B,EAC1B,kBAAkB,EAClB,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { ProtocolQueryDiagnosticsError, ProtocolQueryEventError, } from './errors.js';
2
+ export { DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS } from './limits.js';
3
+ export { validateProtocolQueryDiagnostics, validateProtocolQueryEvent, } from './validate.js';
@@ -0,0 +1,4 @@
1
+ import type { ProtocolQueryEventLimits, ProtocolQueryEventOptions } from './types.js';
2
+ export declare const DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS: Readonly<ProtocolQueryEventLimits>;
3
+ export declare function resolveQueryEventLimits(options?: ProtocolQueryEventOptions): Readonly<ProtocolQueryEventLimits>;
4
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/events/limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,mCAAmC,EAChD,QAAQ,CAAC,wBAAwB,CAG/B,CAAC;AAEH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,yBAA8B,GACtC,QAAQ,CAAC,wBAAwB,CAAC,CAepC"}
@@ -0,0 +1,19 @@
1
+ export const DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS = Object.freeze({
2
+ maxStringBytes: 1_024,
3
+ maxDebugBytes: 4_096,
4
+ });
5
+ export function resolveQueryEventLimits(options = {}) {
6
+ const result = { ...DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS };
7
+ for (const key of Object.keys(result)) {
8
+ const value = options.limits?.[key];
9
+ if (value === undefined)
10
+ continue;
11
+ const maximum = DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS[key];
12
+ if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
13
+ throw new RangeError(`${key} must be a positive safe integer no greater than ${maximum} `
14
+ + '(the query event v1 maximum)');
15
+ }
16
+ result[key] = value;
17
+ }
18
+ return Object.freeze(result);
19
+ }
@@ -0,0 +1,52 @@
1
+ export interface ProtocolQueryEventTarget {
2
+ readonly project: string;
3
+ readonly environment: string;
4
+ }
5
+ export type ProtocolQueryOperation = 'query' | 'command' | 'insert';
6
+ export type ProtocolQueryEventOutcome = 'success' | 'failure';
7
+ /** RFC 0010 version 1 minimum public error categories. */
8
+ export type ProtocolQueryErrorCategory = 'input-invalid' | 'unauthenticated' | 'forbidden' | 'tenant-required' | 'not-found' | 'too-large' | 'aborted' | 'deadline-exceeded' | 'unavailable' | 'internal';
9
+ /** Metadata-only record of one execution. Never carries values, SQL, or credentials. */
10
+ export interface ProtocolQueryEvent {
11
+ readonly kind: 'hypequery-query-event';
12
+ readonly version: 1;
13
+ readonly eventId: string;
14
+ readonly occurredAt: string;
15
+ readonly target: ProtocolQueryEventTarget;
16
+ readonly queryName: string;
17
+ readonly operation: ProtocolQueryOperation;
18
+ readonly outcome: ProtocolQueryEventOutcome;
19
+ /** Required when outcome is 'failure'; forbidden when outcome is 'success'. */
20
+ readonly errorCategory?: ProtocolQueryErrorCategory;
21
+ readonly durationMs: number;
22
+ readonly rowCount?: number;
23
+ /** Derived server-side fingerprint; the raw tenant identifier is prohibited. */
24
+ readonly tenantFingerprint?: string;
25
+ /** External correlation only; never authoritative. */
26
+ readonly correlationId?: string;
27
+ }
28
+ export type ProtocolQueryTerminalReason = 'completed' | 'aborted' | 'deadline-exceeded' | 'drained';
29
+ /** Privileged diagnostics projection; requires the RFC 0009 diagnostic capability. */
30
+ export interface ProtocolQueryDiagnostics {
31
+ readonly kind: 'hypequery-query-diagnostics';
32
+ readonly version: 1;
33
+ readonly eventId: string;
34
+ readonly queryId: string;
35
+ readonly terminalReason: ProtocolQueryTerminalReason;
36
+ readonly attempts: number;
37
+ readonly runtimeIdentity?: string;
38
+ /** Non-executable RFC 0010 debug form; contains no values. */
39
+ readonly debugQuery?: string;
40
+ readonly safeMessage?: string;
41
+ }
42
+ export interface ProtocolQueryEventLimits {
43
+ readonly maxStringBytes: number;
44
+ readonly maxDebugBytes: number;
45
+ }
46
+ /** Parser budgets that may tighten, but not raise, query-event v1 limits. */
47
+ export interface ProtocolQueryEventOptions {
48
+ readonly limits?: Partial<ProtocolQueryEventLimits>;
49
+ }
50
+ export type ProtocolQueryEventErrorCode = 'HQ_EVENT_TYPE' | 'HQ_EVENT_UNKNOWN_FIELD' | 'HQ_EVENT_INVALID_VERSION' | 'HQ_EVENT_INVALID_VALUE' | 'HQ_EVENT_TOO_LARGE' | 'HQ_EVENT_UNSAFE_OBJECT';
51
+ export type ProtocolQueryDiagnosticsErrorCode = 'HQ_DIAGNOSTICS_TYPE' | 'HQ_DIAGNOSTICS_UNKNOWN_FIELD' | 'HQ_DIAGNOSTICS_INVALID_VERSION' | 'HQ_DIAGNOSTICS_INVALID_VALUE' | 'HQ_DIAGNOSTICS_TOO_LARGE' | 'HQ_DIAGNOSTICS_UNSAFE_OBJECT';
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/events/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,MAAM,sBAAsB,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEpE,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,SAAS,CAAC;AAE9D,0DAA0D;AAC1D,MAAM,MAAM,0BAA0B,GAClC,eAAe,GACf,iBAAiB,GACjB,WAAW,GACX,iBAAiB,GACjB,WAAW,GACX,WAAW,GACX,SAAS,GACT,mBAAmB,GACnB,aAAa,GACb,UAAU,CAAC;AAEf,wFAAwF;AACxF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,yBAAyB,C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AM,iCAAiC,GACzC,qBAAqB,GACrB,8BAA8B,GAC9B,gCAAgC,GAChC,8BAA8B,GAC9B,0BAA0B,GAC1B,8BAA8B,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { ProtocolQueryDiagnostics, ProtocolQueryEvent, ProtocolQueryEventOptions } from './types.js';
2
+ export declare function validateProtocolQueryEvent(input: unknown, options?: ProtocolQueryEventOptions): ProtocolQueryEvent;
3
+ export declare function validateProtocolQueryDiagnostics(input: unknown, options?: ProtocolQueryEventOptions): ProtocolQueryDiagnostics;
4
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/events/validate.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,wBAAwB,EAExB,kBAAkB,EAElB,yBAAyB,EAE1B,MAAM,YAAY,CAAC;AA4OpB,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,kBAAkB,CAuDpB;AAED,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,yBAA8B,GACtC,wBAAwB,CA+B1B"}
@@ -0,0 +1,240 @@
1
+ import { ProtocolIdentifierError, parseProtocolQualifiedIdentifier } from '../identifiers/index.js';
2
+ import { ProtocolDeploymentReleaseError, validateProtocolDeploymentReleaseTarget, } from '../releases/index.js';
3
+ import { diagnosticsError, eventError } from './errors.js';
4
+ import { resolveQueryEventLimits } from './limits.js';
5
+ const EVENT_CONTEXT = {
6
+ codes: {
7
+ type: 'HQ_EVENT_TYPE',
8
+ unknownField: 'HQ_EVENT_UNKNOWN_FIELD',
9
+ invalidVersion: 'HQ_EVENT_INVALID_VERSION',
10
+ invalidValue: 'HQ_EVENT_INVALID_VALUE',
11
+ tooLarge: 'HQ_EVENT_TOO_LARGE',
12
+ unsafeObject: 'HQ_EVENT_UNSAFE_OBJECT',
13
+ },
14
+ fail: eventError,
15
+ };
16
+ const DIAGNOSTICS_CONTEXT = {
17
+ codes: {
18
+ type: 'HQ_DIAGNOSTICS_TYPE',
19
+ unknownField: 'HQ_DIAGNOSTICS_UNKNOWN_FIELD',
20
+ invalidVersion: 'HQ_DIAGNOSTICS_INVALID_VERSION',
21
+ invalidValue: 'HQ_DIAGNOSTICS_INVALID_VALUE',
22
+ tooLarge: 'HQ_DIAGNOSTICS_TOO_LARGE',
23
+ unsafeObject: 'HQ_DIAGNOSTICS_UNSAFE_OBJECT',
24
+ },
25
+ fail: diagnosticsError,
26
+ };
27
+ const HEX64_PATTERN = /^[0-9a-f]{64}$/;
28
+ const OCCURRED_AT_PATTERN = /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]{1,3})?Z$/;
29
+ const OPERATIONS = ['query', 'command', 'insert'];
30
+ const OUTCOMES = ['success', 'failure'];
31
+ const ERROR_CATEGORIES = [
32
+ 'input-invalid',
33
+ 'unauthenticated',
34
+ 'forbidden',
35
+ 'tenant-required',
36
+ 'not-found',
37
+ 'too-large',
38
+ 'aborted',
39
+ 'deadline-exceeded',
40
+ 'unavailable',
41
+ 'internal',
42
+ ];
43
+ const TERMINAL_REASONS = ['completed', 'aborted', 'deadline-exceeded', 'drained'];
44
+ const MAX_DURATION_MS = 86_400_000;
45
+ const MAX_ROW_COUNT = 1_000_000_000_000;
46
+ const MAX_ATTEMPTS = 64;
47
+ const textEncoder = new TextEncoder();
48
+ function requireRecord(context, input, path) {
49
+ const { codes, fail } = context;
50
+ if (typeof input !== 'object' || input === null || Array.isArray(input)) {
51
+ fail(codes.type, path);
52
+ }
53
+ const prototype = Object.getPrototypeOf(input);
54
+ if (prototype !== Object.prototype && prototype !== null) {
55
+ fail(codes.unsafeObject, path);
56
+ }
57
+ if (Object.getOwnPropertySymbols(input).length > 0) {
58
+ fail(codes.unsafeObject, path);
59
+ }
60
+ for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(input))) {
61
+ if (!descriptor.enumerable || !('value' in descriptor)) {
62
+ fail(codes.unsafeObject, path);
63
+ }
64
+ }
65
+ return input;
66
+ }
67
+ function exactFields(context, value, required, optional, path) {
68
+ const { codes, fail } = context;
69
+ const allowed = new Set([...required, ...optional]);
70
+ for (const key of Object.keys(value)) {
71
+ if (!allowed.has(key))
72
+ fail(codes.unknownField, `${path}.${key}`);
73
+ }
74
+ for (const key of required) {
75
+ if (!Object.hasOwn(value, key))
76
+ fail(codes.type, `${path}.${key}`);
77
+ }
78
+ }
79
+ function freezeRecord(entries) {
80
+ return Object.freeze(Object.assign(Object.create(null), entries));
81
+ }
82
+ function requireString(context, value, path) {
83
+ if (typeof value !== 'string')
84
+ context.fail(context.codes.type, path);
85
+ return value;
86
+ }
87
+ function hasControlCharacter(text) {
88
+ for (let index = 0; index < text.length; index += 1) {
89
+ const code = text.charCodeAt(index);
90
+ if (code <= 0x1f || (code >= 0x7f && code <= 0x9f))
91
+ return true;
92
+ }
93
+ return false;
94
+ }
95
+ function boundedText(context, value, path, maximum) {
96
+ const text = requireString(context, value, path);
97
+ if (text.length > maximum || textEncoder.encode(text).byteLength > maximum) {
98
+ context.fail(context.codes.tooLarge, path);
99
+ }
100
+ if (hasControlCharacter(text)) {
101
+ context.fail(context.codes.invalidValue, path);
102
+ }
103
+ return text;
104
+ }
105
+ function hexIdentity(context, value, path) {
106
+ const text = requireString(context, value, path);
107
+ if (!HEX64_PATTERN.test(text))
108
+ context.fail(context.codes.invalidValue, path);
109
+ return text;
110
+ }
111
+ function occurredAt(context, value, path) {
112
+ const text = requireString(context, value, path);
113
+ if (!OCCURRED_AT_PATTERN.test(text) || Number.isNaN(Date.parse(text))) {
114
+ context.fail(context.codes.invalidValue, path);
115
+ }
116
+ return text;
117
+ }
118
+ function boundedCount(context, value, path, minimum, maximum) {
119
+ if (typeof value !== 'number')
120
+ context.fail(context.codes.type, path);
121
+ if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
122
+ context.fail(context.codes.invalidValue, path);
123
+ }
124
+ return value;
125
+ }
126
+ function stringChoice(context, value, path, choices) {
127
+ const text = requireString(context, value, path);
128
+ if (!choices.includes(text))
129
+ context.fail(context.codes.invalidValue, path);
130
+ return text;
131
+ }
132
+ function queryTarget(context, value, path) {
133
+ try {
134
+ return validateProtocolDeploymentReleaseTarget(value);
135
+ }
136
+ catch (error) {
137
+ if (error instanceof ProtocolDeploymentReleaseError) {
138
+ context.fail(context.codes.invalidValue, path);
139
+ }
140
+ throw error;
141
+ }
142
+ }
143
+ function queryName(context, value, path) {
144
+ const text = requireString(context, value, path);
145
+ try {
146
+ parseProtocolQualifiedIdentifier(text);
147
+ }
148
+ catch (error) {
149
+ if (error instanceof ProtocolIdentifierError) {
150
+ context.fail(context.codes.invalidValue, path);
151
+ }
152
+ throw error;
153
+ }
154
+ return text;
155
+ }
156
+ function kindAndVersion(context, value, kind) {
157
+ const { codes, fail } = context;
158
+ if (value.kind !== kind) {
159
+ if (typeof value.kind !== 'string')
160
+ fail(codes.type, '$.kind');
161
+ fail(codes.invalidValue, '$.kind');
162
+ }
163
+ if (value.version !== 1) {
164
+ if (typeof value.version !== 'number')
165
+ fail(codes.type, '$.version');
166
+ fail(codes.invalidVersion, '$.version');
167
+ }
168
+ }
169
+ export function validateProtocolQueryEvent(input, options = {}) {
170
+ const limits = resolveQueryEventLimits(options);
171
+ const context = EVENT_CONTEXT;
172
+ const value = requireRecord(context, input, '$');
173
+ exactFields(context, value, [
174
+ 'kind',
175
+ 'version',
176
+ 'eventId',
177
+ 'occurredAt',
178
+ 'target',
179
+ 'queryName',
180
+ 'operation',
181
+ 'outcome',
182
+ 'durationMs',
183
+ ], ['errorCategory', 'rowCount', 'tenantFingerprint', 'correlationId'], '$');
184
+ kindAndVersion(context, value, 'hypequery-query-event');
185
+ const outcome = stringChoice(context, value.outcome, '$.outcome', OUTCOMES);
186
+ const hasCategory = Object.hasOwn(value, 'errorCategory');
187
+ if (outcome === 'failure' && !hasCategory) {
188
+ eventError('HQ_EVENT_INVALID_VALUE', '$.errorCategory');
189
+ }
190
+ if (outcome === 'success' && hasCategory) {
191
+ eventError('HQ_EVENT_INVALID_VALUE', '$.errorCategory');
192
+ }
193
+ return freezeRecord({
194
+ kind: 'hypequery-query-event',
195
+ version: 1,
196
+ eventId: hexIdentity(context, value.eventId, '$.eventId'),
197
+ occurredAt: occurredAt(context, value.occurredAt, '$.occurredAt'),
198
+ target: queryTarget(context, value.target, '$.target'),
199
+ queryName: queryName(context, value.queryName, '$.queryName'),
200
+ operation: stringChoice(context, value.operation, '$.operation', OPERATIONS),
201
+ outcome,
202
+ ...(hasCategory ? {
203
+ errorCategory: stringChoice(context, value.errorCategory, '$.errorCategory', ERROR_CATEGORIES),
204
+ } : {}),
205
+ durationMs: boundedCount(context, value.durationMs, '$.durationMs', 0, MAX_DURATION_MS),
206
+ ...(Object.hasOwn(value, 'rowCount') ? {
207
+ rowCount: boundedCount(context, value.rowCount, '$.rowCount', 0, MAX_ROW_COUNT),
208
+ } : {}),
209
+ ...(Object.hasOwn(value, 'tenantFingerprint') ? {
210
+ tenantFingerprint: hexIdentity(context, value.tenantFingerprint, '$.tenantFingerprint'),
211
+ } : {}),
212
+ ...(Object.hasOwn(value, 'correlationId') ? {
213
+ correlationId: boundedText(context, value.correlationId, '$.correlationId', limits.maxStringBytes),
214
+ } : {}),
215
+ });
216
+ }
217
+ export function validateProtocolQueryDiagnostics(input, options = {}) {
218
+ const limits = resolveQueryEventLimits(options);
219
+ const context = DIAGNOSTICS_CONTEXT;
220
+ const value = requireRecord(context, input, '$');
221
+ exactFields(context, value, ['kind', 'version', 'eventId', 'queryId', 'terminalReason', 'attempts'], ['runtimeIdentity', 'debugQuery', 'safeMessage'], '$');
222
+ kindAndVersion(context, value, 'hypequery-query-diagnostics');
223
+ return freezeRecord({
224
+ kind: 'hypequery-query-diagnostics',
225
+ version: 1,
226
+ eventId: hexIdentity(context, value.eventId, '$.eventId'),
227
+ queryId: hexIdentity(context, value.queryId, '$.queryId'),
228
+ terminalReason: stringChoice(context, value.terminalReason, '$.terminalReason', TERMINAL_REASONS),
229
+ attempts: boundedCount(context, value.attempts, '$.attempts', 1, MAX_ATTEMPTS),
230
+ ...(Object.hasOwn(value, 'runtimeIdentity') ? {
231
+ runtimeIdentity: hexIdentity(context, value.runtimeIdentity, '$.runtimeIdentity'),
232
+ } : {}),
233
+ ...(Object.hasOwn(value, 'debugQuery') ? {
234
+ debugQuery: boundedText(context, value.debugQuery, '$.debugQuery', limits.maxDebugBytes),
235
+ } : {}),
236
+ ...(Object.hasOwn(value, 'safeMessage') ? {
237
+ safeMessage: boundedText(context, value.safeMessage, '$.safeMessage', limits.maxStringBytes),
238
+ } : {}),
239
+ });
240
+ }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export type { ProtocolSchema, ProtocolSchemaErrorCode, ProtocolSchemaLimits, Pro
7
7
  export type { ProtocolAggregation, ProtocolBinaryOperator, ProtocolComparisonOperator, ProtocolDatasetQuery, ProtocolExpression, ProtocolExpressionErrorCode, ProtocolExpressionLimits, ProtocolExpressionOptions, ProtocolFunctionName, ProtocolMetricQuery, ProtocolOrderBy, ProtocolSemanticQuery, ProtocolTimeGrain, } from './expressions/index.js';
8
8
  export type { ProtocolIdentifier, ProtocolIdentifierErrorCode, ProtocolQualifiedIdentifier, } from './identifiers/index.js';
9
9
  export { DEFAULT_PROTOCOL_QUERY_IMPLEMENTATION_LIMITS, ProtocolQueryImplementationError, validateProtocolQueryImplementation, validateProtocolSqlExpression, } from './query-implementations/index.js';
10
+ export { DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS, ProtocolQueryDiagnosticsError, ProtocolQueryEventError, validateProtocolQueryDiagnostics, validateProtocolQueryEvent, } from './events/index.js';
11
+ export type { ProtocolQueryDiagnostics, ProtocolQueryDiagnosticsErrorCode, ProtocolQueryErrorCategory, ProtocolQueryEvent, ProtocolQueryEventErrorCode, ProtocolQueryEventLimits, ProtocolQueryEventOptions, ProtocolQueryEventOutcome, ProtocolQueryEventTarget, ProtocolQueryOperation, ProtocolQueryTerminalReason, } from './events/index.js';
10
12
  export { DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS, PROTOCOL_DEPLOYMENT_BUNDLE_IDENTITY_DOMAIN, ProtocolDeploymentBundleError, encodeProtocolDeploymentBundleManifest, encodeProtocolDeploymentBundleManifestToString, hashProtocolDeploymentBundleManifest, prepareProtocolDeploymentBundleManifest, validateProtocolDeploymentBundleManifest, } from './bundles/index.js';
11
13
  export { DEFAULT_PROTOCOL_DEPLOYMENT_RELEASE_LIMITS, PROTOCOL_DEPLOYMENT_RELEASE_IDENTITY_DOMAIN, ProtocolDeploymentReleaseError, encodeProtocolDeploymentReleaseEnvelope, encodeProtocolDeploymentReleaseEnvelopeToString, hashProtocolDeploymentReleaseEnvelope, prepareProtocolDeploymentReleaseEnvelope, validateProtocolDeploymentReleaseEnvelope, validateProtocolDeploymentReleaseTarget, } from './releases/index.js';
12
14
  export type { PreparedProtocolDeploymentReleaseEnvelope, ProtocolDeploymentReleaseEnvelope, ProtocolDeploymentReleaseErrorCode, ProtocolDeploymentReleaseLimits, ProtocolDeploymentReleaseOptions, ProtocolDeploymentReleaseTarget, } from './releases/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,sBAAsB,EACtB,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,m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,EACrC,wCAAwC,EACxC,yCAAyC,EACzC,uCAAuC,GACxC,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,yCAAyC,EACzC,iCAAiC,EACjC,kCAAkC,EAClC,+BAA+B,EAC/B,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,wCAAwC,EACxC,gCAAgC,EAChC,kCAAkC,EAClC,iCAAiC,EACjC,4BAA4B,EAC5B,8BAA8B,EAC9B,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,kCAAkC,EAClC,mCAAmC,EACnC,uBAAuB,EACvB,gCAAgC,EAChC,wCAAwC,EACxC,8BAA8B,EAC9B,iCAAiC,EACjC,+BAA+B,EAC/B,kCAAkC,GACnC,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,kCAAkC,EAClC,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,iCAAiC,EACjC,kCAAkC,EAClC,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,kCAAkC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,mBAAmB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BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,iCAAiC,EACjC,kCAAkC,EAClC,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,kCAAkC,CAAC"}
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export { PROTOCOL_IDENTIFIER_LIMITS, ProtocolIdentifierError, isProtocolIdentifi
3
3
  export { DEFAULT_PROTOCOL_EXPRESSION_LIMITS, ProtocolExpressionError, validateProtocolExpression, validateProtocolSemanticQuery, } from './expressions/index.js';
4
4
  export { DEFAULT_PROTOCOL_SCHEMA_LIMITS, DEFAULT_PROTOCOL_SCHEMA_VALUE_LIMITS, ProtocolSchemaError, ProtocolSchemaValueError, applyProtocolSchemaValue, createProtocolSchemaValueParser, resolveProtocolSchemaValueLimits, validateProtocolSchema, } from './schemas/index.js';
5
5
  export { DEFAULT_PROTOCOL_QUERY_IMPLEMENTATION_LIMITS, ProtocolQueryImplementationError, validateProtocolQueryImplementation, validateProtocolSqlExpression, } from './query-implementations/index.js';
6
+ export { DEFAULT_PROTOCOL_QUERY_EVENT_LIMITS, ProtocolQueryDiagnosticsError, ProtocolQueryEventError, validateProtocolQueryDiagnostics, validateProtocolQueryEvent, } from './events/index.js';
6
7
  export { DEFAULT_PROTOCOL_DEPLOYMENT_BUNDLE_LIMITS, PROTOCOL_DEPLOYMENT_BUNDLE_IDENTITY_DOMAIN, ProtocolDeploymentBundleError, encodeProtocolDeploymentBundleManifest, encodeProtocolDeploymentBundleManifestToString, hashProtocolDeploymentBundleManifest, prepareProtocolDeploymentBundleManifest, validateProtocolDeploymentBundleManifest, } from './bundles/index.js';
7
8
  export { DEFAULT_PROTOCOL_DEPLOYMENT_RELEASE_LIMITS, PROTOCOL_DEPLOYMENT_RELEASE_IDENTITY_DOMAIN, ProtocolDeploymentReleaseError, encodeProtocolDeploymentReleaseEnvelope, encodeProtocolDeploymentReleaseEnvelopeToString, hashProtocolDeploymentReleaseEnvelope, prepareProtocolDeploymentReleaseEnvelope, validateProtocolDeploymentReleaseEnvelope, validateProtocolDeploymentReleaseTarget, } from './releases/index.js';
8
9
  export { DEFAULT_PROTOCOL_DEPLOYMENT_LIMITS, PROTOCOL_DEPLOYMENT_IDENTITY_DOMAIN, ProtocolDeploymentError, encodeProtocolDeploymentContract, encodeProtocolDeploymentContractToString, hashProtocolDeploymentContract, prepareProtocolDeploymentContract, validateProtocolDatasetContract, validateProtocolDeploymentContract, } from './deployments/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypequery/protocol",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Public contracts and TypeScript reference implementation for portable Hypequery artifacts",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",