liminal 0.5.15 → 0.5.17
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/{Model.ts → Adapter.ts} +3 -3
- package/{ModelRegistry.ts → AdapterRegistry.ts} +24 -14
- package/CHANGELOG.md +12 -0
- package/Config.ts +2 -2
- package/Context.ts +4 -4
- package/L/L.ts +1 -1
- package/L/focus.ts +17 -0
- package/L/infer.ts +2 -4
- package/L/run.ts +2 -3
- package/L/schema/_schema_common.ts +2 -1
- package/L/stream.ts +3 -5
- package/L/system.ts +2 -1
- package/L/user.ts +2 -1
- package/LEvent.ts +5 -5
- package/dist/{Model.d.ts → Adapter.d.ts} +3 -3
- package/dist/Adapter.js +13 -0
- package/dist/Adapter.js.map +1 -0
- package/dist/AdapterRegistry.d.ts +27 -0
- package/dist/{ModelRegistry.js → AdapterRegistry.js} +18 -12
- package/dist/AdapterRegistry.js.map +1 -0
- package/dist/Config.d.ts +2 -2
- package/dist/Config.js +1 -1
- package/dist/Config.js.map +1 -1
- package/dist/Context.d.ts +2 -2
- package/dist/Context.js +3 -3
- package/dist/Context.js.map +1 -1
- package/dist/L/L.d.ts +1 -1
- package/dist/L/L.js +1 -1
- package/dist/L/L.js.map +1 -1
- package/dist/L/{model.d.ts → focus.d.ts} +2 -2
- package/dist/L/focus.js +14 -0
- package/dist/L/focus.js.map +1 -0
- package/dist/L/infer.js +2 -4
- package/dist/L/infer.js.map +1 -1
- package/dist/L/run.d.ts +0 -2
- package/dist/L/run.js +2 -2
- package/dist/L/run.js.map +1 -1
- package/dist/L/schema/_schema_common.js +2 -1
- package/dist/L/schema/_schema_common.js.map +1 -1
- package/dist/L/stream.js +3 -5
- package/dist/L/stream.js.map +1 -1
- package/dist/L/system.js +2 -1
- package/dist/L/system.js.map +1 -1
- package/dist/L/user.js +2 -1
- package/dist/L/user.js.map +1 -1
- package/dist/LEvent.d.ts +7 -7
- package/dist/LEvent.js +4 -4
- package/dist/LEvent.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/util/fixTemplateStrings.d.ts +11 -0
- package/dist/util/fixTemplateStrings.js +83 -0
- package/dist/util/fixTemplateStrings.js.map +1 -0
- package/index.ts +2 -2
- package/package.json +1 -1
- package/util/fixTemplateStrings.ts +99 -0
- package/L/model.ts +0 -17
- package/dist/L/model.js +0 -14
- package/dist/L/model.js.map +0 -1
- package/dist/Model.js +0 -13
- package/dist/Model.js.map +0 -1
- package/dist/ModelRegistry.d.ts +0 -25
- package/dist/ModelRegistry.js.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const INDENTATION_RE = /^\n([ \t]+)/
|
|
2
|
+
const ESCAPE_SEQ_RE = /\\([`${\\]|\n)/g
|
|
3
|
+
const LAST_INDENTATION_RE = /\n[ \t]+$/
|
|
4
|
+
|
|
5
|
+
export function fixTemplateStrings(template: TemplateStringsArray): { readonly raw: readonly string[] } {
|
|
6
|
+
const firstSegment = template.raw[0]!
|
|
7
|
+
const leadingIndentMatch = INDENTATION_RE.exec(firstSegment)
|
|
8
|
+
const indentation = leadingIndentMatch?.[1]
|
|
9
|
+
|
|
10
|
+
const rawLength = template.raw.length
|
|
11
|
+
const result = new Array(rawLength)
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < rawLength; i++) {
|
|
14
|
+
let str = template.raw[i]!
|
|
15
|
+
// Only perform common indentation replacements if needed
|
|
16
|
+
if (indentation) {
|
|
17
|
+
// Remove leading newline and indentation in the first segment
|
|
18
|
+
if (i === 0) {
|
|
19
|
+
str = str.slice(indentation.length + 1)
|
|
20
|
+
}
|
|
21
|
+
// Use a simple string replacement with a regular expression for better performance
|
|
22
|
+
str = str.replaceAll(`\n${indentation}`, "\n")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Replace common escape sequences in a single pass
|
|
26
|
+
str = str.replace(ESCAPE_SEQ_RE, (_match, char) => {
|
|
27
|
+
// Keep the escaped newline replacement separate for clarity
|
|
28
|
+
return char === "\n" ? "" : char
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// Handle trailing spaces only for the last segment
|
|
32
|
+
if (indentation && i === rawLength - 1) {
|
|
33
|
+
str = str.replace(LAST_INDENTATION_RE, "")
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
result[i] = str
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return { raw: result }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const LEADING_SPACE_RE = /^([ \t]*)/
|
|
43
|
+
/**
|
|
44
|
+
* Applies template string indentation to substituted values with line breaks
|
|
45
|
+
*
|
|
46
|
+
* @param strings - The template strings array (processed through fixTemplateStrings)
|
|
47
|
+
* @param values - The substitution values
|
|
48
|
+
* @returns - The formatted string with properly indented substitutions
|
|
49
|
+
*/
|
|
50
|
+
export function applyTemplateWithIndentation(strings: TemplateStringsArray, ...values: any[]): string {
|
|
51
|
+
const fixedStrings = fixTemplateStrings(strings)
|
|
52
|
+
const rawArr = fixedStrings.raw
|
|
53
|
+
const valuesLength = values.length
|
|
54
|
+
|
|
55
|
+
const resultParts = new Array(Math.max(1, rawArr.length * 2 - 1))
|
|
56
|
+
let resultIndex = 0
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < rawArr.length; i++) {
|
|
59
|
+
const str = rawArr[i] || ""
|
|
60
|
+
resultParts[resultIndex++] = str
|
|
61
|
+
|
|
62
|
+
// Only process values for non-final segments
|
|
63
|
+
if (i < valuesLength) {
|
|
64
|
+
const value = String(values[i])
|
|
65
|
+
|
|
66
|
+
// If value has line breaks, we should indent it
|
|
67
|
+
if (value.includes("\n")) {
|
|
68
|
+
const lastNewlineIndex = str.lastIndexOf("\n")
|
|
69
|
+
|
|
70
|
+
if (lastNewlineIndex !== -1) {
|
|
71
|
+
// Extract the indentation after the last newline
|
|
72
|
+
const textAfterLastNewline = str.substring(lastNewlineIndex + 1)
|
|
73
|
+
const leadingSpaceMatch = LEADING_SPACE_RE.exec(textAfterLastNewline)
|
|
74
|
+
const indentationToApply = leadingSpaceMatch && leadingSpaceMatch[1] ? leadingSpaceMatch[1] : ""
|
|
75
|
+
|
|
76
|
+
if (indentationToApply) {
|
|
77
|
+
// Split the value into lines once
|
|
78
|
+
const lines = value.split("\n")
|
|
79
|
+
const linesLength = lines.length
|
|
80
|
+
|
|
81
|
+
// First line doesn't need indentation
|
|
82
|
+
resultParts[resultIndex++] = lines[0]
|
|
83
|
+
|
|
84
|
+
// Apply indentation to subsequent lines
|
|
85
|
+
for (let j = 1; j < linesLength; j++) {
|
|
86
|
+
resultParts[resultIndex++] = "\n" + indentationToApply + lines[j]
|
|
87
|
+
}
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// For simple values or when no indentation is needed
|
|
93
|
+
resultParts[resultIndex++] = value
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Combine all parts at once
|
|
98
|
+
return resultParts.slice(0, resultIndex).join("")
|
|
99
|
+
}
|
package/L/model.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { LEvent } from "../LEvent.ts"
|
|
2
|
-
import { ModelRegistered } from "../LEvent.ts"
|
|
3
|
-
import type { Model } from "../Model.ts"
|
|
4
|
-
import type { Rune } from "../Rune.ts"
|
|
5
|
-
import { emit } from "./emit.ts"
|
|
6
|
-
import { reflect } from "./reflect.ts"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Registers a model in the current context and emits a model registration event.
|
|
10
|
-
* Returns the registered model instance.
|
|
11
|
-
*/
|
|
12
|
-
export function* model(model: Model): Generator<Rune<LEvent>, Model> {
|
|
13
|
-
const { context: { models } } = yield* reflect
|
|
14
|
-
models.register(model)
|
|
15
|
-
yield* emit(new ModelRegistered(model))
|
|
16
|
-
return model
|
|
17
|
-
}
|
package/dist/L/model.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ModelRegistered } from "../LEvent.js";
|
|
2
|
-
import { emit } from "./emit.js";
|
|
3
|
-
import { reflect } from "./reflect.js";
|
|
4
|
-
/**
|
|
5
|
-
* Registers a model in the current context and emits a model registration event.
|
|
6
|
-
* Returns the registered model instance.
|
|
7
|
-
*/
|
|
8
|
-
export function* model(model) {
|
|
9
|
-
const { context: { models } } = yield* reflect;
|
|
10
|
-
models.register(model);
|
|
11
|
-
yield* emit(new ModelRegistered(model));
|
|
12
|
-
return model;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=model.js.map
|
package/dist/L/model.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../L/model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC;;;GAGG;AACH,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,KAAY;IACjC,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAA;IAC9C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACtB,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC,CAAA;IACvC,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/Model.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { attachCustomInspect } from "./util/attachCustomInspect.js";
|
|
2
|
-
export class Model {
|
|
3
|
-
client;
|
|
4
|
-
seal;
|
|
5
|
-
constructor(client, seal) {
|
|
6
|
-
this.client = client;
|
|
7
|
-
this.seal = seal;
|
|
8
|
-
}
|
|
9
|
-
static {
|
|
10
|
-
attachCustomInspect(this, ({ client }) => ({ client }));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=Model.js.map
|
package/dist/Model.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Model.js","sourceRoot":"","sources":["../Model.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAEnE,MAAM,OAAO,KAAK;IAEL;IACA;IAFX,YACW,MAAc,EACd,IAA4C;QAD5C,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAwC;IACpD,CAAC;IAEJ;QACE,mBAAmB,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;IACzD,CAAC;CACF"}
|
package/dist/ModelRegistry.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Model } from "./Model.ts";
|
|
2
|
-
/**
|
|
3
|
-
* An intrusive doubly-linked list for storing `Model`s.
|
|
4
|
-
* Provides efficient insertion, removal, and lookups.
|
|
5
|
-
*/
|
|
6
|
-
export declare class ModelRegistry {
|
|
7
|
-
head?: ModelRegistryNode | undefined;
|
|
8
|
-
tail?: ModelRegistryNode | undefined;
|
|
9
|
-
/** Returns the most recently registered model */
|
|
10
|
-
peek(): Model | undefined;
|
|
11
|
-
/**
|
|
12
|
-
* Registers a new model and returns the created node
|
|
13
|
-
* @param value The model to register
|
|
14
|
-
*/
|
|
15
|
-
register(value: Model): ModelRegistryNode;
|
|
16
|
-
/** Remove a model from the registry. */
|
|
17
|
-
remove(node: ModelRegistryNode): void;
|
|
18
|
-
/** Creates a deep copy of this registry. */
|
|
19
|
-
clone(): ModelRegistry;
|
|
20
|
-
}
|
|
21
|
-
export interface ModelRegistryNode {
|
|
22
|
-
prev: ModelRegistryNode | undefined;
|
|
23
|
-
model: Model;
|
|
24
|
-
next?: Mod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