@patterkit/core 0.2.2 → 0.2.4

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/dist/index.cjs CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  gameIdify: () => import_model4.gameIdify,
26
26
  hash32: () => hash32,
27
27
  hash4: () => hash4,
28
+ humanizeNodeRefs: () => humanizeNodeRefs,
28
29
  isValidGameId: () => import_model4.isValidGameId,
29
30
  newId: () => import_toolkit.newId,
30
31
  parseSource: () => import_toolkit3.parseSource,
@@ -52,6 +53,12 @@ function hash32(input) {
52
53
  // src/index.ts
53
54
  var import_model4 = require("@patterkit/model");
54
55
 
56
+ // src/noderefs.ts
57
+ var VISIT_FN_RE = /\b(patter_visits|patter_seen|visits|seen)\s*\(\s*(?:(['"])(.*?)\2|([A-Za-z_]\w*))\s*\)/g;
58
+ function humanizeNodeRefs(cond, label) {
59
+ return cond.replace(VISIT_FN_RE, (_m, fn, _q, quoted, bare) => `${fn}(${label(quoted ?? bare ?? "")})`);
60
+ }
61
+
55
62
  // src/serialize.ts
56
63
  var import_json5 = require("json5");
57
64
  var import_toolkit3 = require("@wildwinter/toolkit");
@@ -472,6 +479,7 @@ function defaultMatchesType(value, decl) {
472
479
  gameIdify,
473
480
  hash32,
474
481
  hash4,
482
+ humanizeNodeRefs,
475
483
  isValidGameId,
476
484
  newId,
477
485
  parseSource,
package/dist/index.d.cts CHANGED
@@ -9,6 +9,13 @@ declare function hash4(input: string): string;
9
9
  /** Deterministic 7-char base-36 hash of a string (full FNV-1a 32-bit width) - e.g. content hashes. */
10
10
  declare function hash32(input: string): string;
11
11
 
12
+ /**
13
+ * Rewrite every `visits(id)` / `seen(id)` in `cond` with `label(id)` in place of the id, leaving the
14
+ * rest of the expression untouched. `label` returns the id itself for anything it cannot name, so an
15
+ * id that no longer resolves still reads as it always did rather than vanishing.
16
+ */
17
+ declare function humanizeNodeRefs(cond: string, label: (id: string) => string): string;
18
+
12
19
  /** Options for {@link canonicalStringify}. */
13
20
  interface StringifyOptions {
14
21
  /** Emit a trailing comma after the last item/entry (the canonical SOURCE form).
@@ -33,4 +40,4 @@ interface ProjectInput {
33
40
  /** Validate a project's structural invariants. Returns an empty array when valid. */
34
41
  declare function validateProject(input: ProjectInput): ValidationIssue[];
35
42
 
36
- export { type ProjectInput, type StringifyOptions, type ValidationIssue, canonicalStringify, hash32, hash4, slug, validateProject };
43
+ export { type ProjectInput, type StringifyOptions, type ValidationIssue, canonicalStringify, hash32, hash4, humanizeNodeRefs, slug, validateProject };
package/dist/index.d.ts CHANGED
@@ -9,6 +9,13 @@ declare function hash4(input: string): string;
9
9
  /** Deterministic 7-char base-36 hash of a string (full FNV-1a 32-bit width) - e.g. content hashes. */
10
10
  declare function hash32(input: string): string;
11
11
 
12
+ /**
13
+ * Rewrite every `visits(id)` / `seen(id)` in `cond` with `label(id)` in place of the id, leaving the
14
+ * rest of the expression untouched. `label` returns the id itself for anything it cannot name, so an
15
+ * id that no longer resolves still reads as it always did rather than vanishing.
16
+ */
17
+ declare function humanizeNodeRefs(cond: string, label: (id: string) => string): string;
18
+
12
19
  /** Options for {@link canonicalStringify}. */
13
20
  interface StringifyOptions {
14
21
  /** Emit a trailing comma after the last item/entry (the canonical SOURCE form).
@@ -33,4 +40,4 @@ interface ProjectInput {
33
40
  /** Validate a project's structural invariants. Returns an empty array when valid. */
34
41
  declare function validateProject(input: ProjectInput): ValidationIssue[];
35
42
 
36
- export { type ProjectInput, type StringifyOptions, type ValidationIssue, canonicalStringify, hash32, hash4, slug, validateProject };
43
+ export { type ProjectInput, type StringifyOptions, type ValidationIssue, canonicalStringify, hash32, hash4, humanizeNodeRefs, slug, validateProject };
package/dist/index.js CHANGED
@@ -17,6 +17,12 @@ function hash32(input) {
17
17
  // src/index.ts
18
18
  import { gameIdify, isValidGameId as isValidGameId2, effectiveGameId as effectiveGameId2 } from "@patterkit/model";
19
19
 
20
+ // src/noderefs.ts
21
+ var VISIT_FN_RE = /\b(patter_visits|patter_seen|visits|seen)\s*\(\s*(?:(['"])(.*?)\2|([A-Za-z_]\w*))\s*\)/g;
22
+ function humanizeNodeRefs(cond, label) {
23
+ return cond.replace(VISIT_FN_RE, (_m, fn, _q, quoted, bare) => `${fn}(${label(quoted ?? bare ?? "")})`);
24
+ }
25
+
20
26
  // src/serialize.ts
21
27
  import "json5";
22
28
  import { parseSource } from "@wildwinter/toolkit";
@@ -436,6 +442,7 @@ export {
436
442
  gameIdify,
437
443
  hash32,
438
444
  hash4,
445
+ humanizeNodeRefs,
439
446
  isValidGameId2 as isValidGameId,
440
447
  newId,
441
448
  parseSource,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patterkit/core",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Patter core: stable id generation, readable-handle computation, canonical (de)serialisation, and the structural validator.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts --clean"
35
35
  },
36
36
  "dependencies": {
37
- "@patterkit/model": "0.4.1",
37
+ "@patterkit/model": "0.5.0",
38
38
  "@wildwinter/toolkit": "^0.1.0",
39
39
  "json5": "^2.2.3"
40
40
  }