@openframe-org/criteria-set-protocol 2.7.6 → 2.7.8-alpha.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.
@@ -0,0 +1,2 @@
1
+ export type HashableConfiguration = Record<string, string | string[]>;
2
+ export declare const hashConfiguration: (configuration: HashableConfiguration) => string;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hashConfiguration = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const utils_1 = require("./utils");
6
+ const normalizeText = (text) => {
7
+ return text.normalize("NFC");
8
+ };
9
+ const isValidConfigurationValue = (value) => {
10
+ if (typeof value === "string") {
11
+ return true;
12
+ }
13
+ if (!Array.isArray(value)) {
14
+ return false;
15
+ }
16
+ for (const childValue of value) {
17
+ if (typeof childValue !== "string") {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ };
23
+ const compareUtf8 = (stringA, stringB) => {
24
+ const bufferA = Buffer.from(stringA, "utf8");
25
+ const bufferB = Buffer.from(stringB, "utf8");
26
+ const minimum = Math.min(bufferA.length, bufferB.length);
27
+ for (let index = 0; index < minimum; index++) {
28
+ const difference = bufferA[index] - bufferB[index];
29
+ if (difference !== 0) {
30
+ return difference;
31
+ }
32
+ }
33
+ return bufferA.length - bufferB.length;
34
+ };
35
+ const canonicalizeStringConfiguration = (configuration) => {
36
+ if ((0, utils_1.isNil)(configuration) || typeof configuration !== "object" || Array.isArray(configuration)) {
37
+ throw new Error("Cannot canonicalize configuration objects that are not string maps of strings or arrays of strings");
38
+ }
39
+ const parts = [];
40
+ const normalizedConfiguration = {};
41
+ for (const [key, value] of Object.entries(configuration)) {
42
+ normalizedConfiguration[normalizeText(key)] = value;
43
+ }
44
+ for (const key of Object.keys(normalizedConfiguration).sort(compareUtf8)) {
45
+ const rawValue = normalizedConfiguration[key];
46
+ if (!isValidConfigurationValue(rawValue)) {
47
+ throw new Error(`Invalid configuration value for '${key}': ${rawValue}`);
48
+ }
49
+ const encodedKey = JSON.stringify(key);
50
+ let encodedValue;
51
+ if (typeof rawValue === "string") {
52
+ encodedValue = JSON.stringify(normalizeText(rawValue));
53
+ }
54
+ else {
55
+ const normalized = rawValue.map(normalizeText).sort(compareUtf8);
56
+ encodedValue = `[${normalized.map((entry) => JSON.stringify(entry)).join(",")}]`;
57
+ }
58
+ parts.push(`${encodedKey}:${encodedValue}`);
59
+ }
60
+ return `{${parts.join(",")}}`;
61
+ };
62
+ const hashConfiguration = (configuration) => {
63
+ const canonical = canonicalizeStringConfiguration(configuration);
64
+ return (0, node_crypto_1.createHash)("sha256").update(canonical, "utf8").digest("hex");
65
+ };
66
+ exports.hashConfiguration = hashConfiguration;
@@ -1,5 +1,6 @@
1
1
  export * from "./schemas";
2
2
  export * from "./services";
3
3
  export * from "./types";
4
+ export * from "./functions";
4
5
  export * from "./utils";
5
6
  export * from "./errors";
package/dist/v1/index.js CHANGED
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./schemas"), exports);
18
18
  __exportStar(require("./services"), exports);
19
19
  __exportStar(require("./types"), exports);
20
+ __exportStar(require("./functions"), exports);
20
21
  __exportStar(require("./utils"), exports);
21
22
  __exportStar(require("./errors"), exports);
@@ -13,8 +13,8 @@ export declare const metadataSchema: z.ZodObject<{
13
13
  shortName: z.ZodString;
14
14
  group: z.ZodString;
15
15
  description: z.ZodString;
16
- documentation: z.ZodOptional<z.ZodString>;
17
- schemas: z.ZodOptional<z.ZodObject<{
16
+ documentation: z.ZodNullable<z.ZodString>;
17
+ schemas: z.ZodNullable<z.ZodObject<{
18
18
  properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
19
19
  parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
20
20
  }, z.core.$strip>>;
@@ -29,10 +29,10 @@ exports.metadataSchema = zod_1.z
29
29
  .describe("A detailed description of the criteria set"),
30
30
  documentation: zod_1.z
31
31
  .string()
32
- .optional()
32
+ .nullable()
33
33
  .describe("Additional documentation or usage guidelines for the criteria set"),
34
34
  schemas: exports.schemaDefinitionsSchema
35
- .optional()
35
+ .nullable()
36
36
  .describe("Definitions of property, parameter and result schemas for the criteria set"),
37
37
  })
38
38
  .describe("Metadata - The metadata for a criteria set");
@@ -8,8 +8,8 @@ export declare const criteriaSetsAndVersionsSchema: z.ZodRecord<z.ZodString, z.Z
8
8
  shortName: z.ZodString;
9
9
  group: z.ZodString;
10
10
  description: z.ZodString;
11
- documentation: z.ZodOptional<z.ZodString>;
12
- schemas: z.ZodOptional<z.ZodObject<{
11
+ documentation: z.ZodNullable<z.ZodString>;
12
+ schemas: z.ZodNullable<z.ZodObject<{
13
13
  properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
14
14
  parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
15
15
  }, z.core.$strip>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openframe-org/criteria-set-protocol",
3
- "version": "2.7.6",
3
+ "version": "2.7.8-alpha.0",
4
4
  "description": "A protocol and tools for defining and working with criteria sets",
5
5
  "private": false,
6
6
  "author": "Andrés Angulo <aa@openframe.org>",