mirror of
https://github.com/gorules/zen.git
synced 2026-10-04 16:02:18 +00:00
* feat: implement slots instead of natural language Replace the natural-language projection (`nl`) with engine-owned slot completion: for a cursor position the engine classifies the slot being edited (operand, operator, literal, member access, ...) and returns typed options, literal facts and the expected type, for policies and graphs. - zen-expression: new `slot` module (classification, literals, operators) and a lenient lexer mode for incomplete input; `nl` removed - Intellisense: typed diagnostic codes with arguments, richer inspect for hover, dedicated parser error variants (messages unchanged) - Engine: `Workspace::cursor_scope`, `slot`, `facts`; `rename_from` and `references_from`; editor spans in UTF-16 units; renames reach imported policies, `$nodes` reads, child graphs and output column heads; no `$root` completion in policies - Node bindings: `slot`, `facts`, `cursorScope`, `slotBatch` replace `nl`, `nlTokenize`, `nlEncodeString`, `nlTokenizeBatch` No change to expression evaluation: the VM, compiler, functions and the default lexer path are untouched, and parser error messages keep their text. * fix: harden slot classification, scopes and graph expectations - restore master execution order; slot scopes hide writes of the edited block and its dependents instead of relying on block ranking - token-start editing gated by slot state; operator, list and operand spans no longer splice into neighbouring tokens - interval-aware bracket pairing for half-open and reversed intervals - lenient lexer recovers from unknown characters (slots only) - graph expected type follows switch and pass-through nodes and merges compatible output schemas - sibling inference caps distinct values and analyses lazily - deterministic overload return type display * fix: order policy blocks by entity reads through closures and relationships - record reads for `#.field` in closures so entity fields read through lists become dependencies - link reads through derived lists (filter/map results) to the entity fields they carry and order the list after those fields - evaluate entity blocks on single relationships, and demand entity paths for plain reads through relationships - slot scopes keep the top-level variable when hiding written fields
124 lines
4.3 KiB
JavaScript
124 lines
4.3 KiB
JavaScript
/* eslint-disable */
|
|
/* prettier-ignore */
|
|
|
|
/* auto-generated by NAPI-RS */
|
|
|
|
const __nodeFs = require('node:fs')
|
|
const __nodePath = require('node:path')
|
|
const { WASI: __nodeWASI } = require('node:wasi')
|
|
const { Worker } = require('node:worker_threads')
|
|
|
|
const {
|
|
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
getDefaultContext: __emnapiGetDefaultContext,
|
|
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
} = require('@napi-rs/wasm-runtime')
|
|
|
|
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
|
|
const __wasi = new __nodeWASI({
|
|
version: 'preview1',
|
|
env: process.env,
|
|
preopens: {
|
|
[__rootDir]: __rootDir,
|
|
}
|
|
})
|
|
|
|
const __emnapiContext = __emnapiGetDefaultContext()
|
|
|
|
const __sharedMemory = new WebAssembly.Memory({
|
|
initial: 1024,
|
|
maximum: 16384,
|
|
shared: true,
|
|
})
|
|
|
|
let __wasmFilePath = __nodePath.join(__dirname, 'zen-engine.wasm32-wasi.wasm')
|
|
const __wasmDebugFilePath = __nodePath.join(__dirname, 'zen-engine.wasm32-wasi.debug.wasm')
|
|
|
|
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
__wasmFilePath = __wasmDebugFilePath
|
|
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
try {
|
|
__wasmFilePath = __nodePath.resolve('@gorules/zen-engine-wasm32-wasi')
|
|
} catch {
|
|
throw new Error('Cannot find zen-engine.wasm32-wasi.wasm file, and @gorules/zen-engine-wasm32-wasi package is not installed.')
|
|
}
|
|
}
|
|
|
|
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
context: __emnapiContext,
|
|
asyncWorkPoolSize: (function() {
|
|
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
// NaN > 0 is false
|
|
if (threadsSizeFromEnv > 0) {
|
|
return threadsSizeFromEnv
|
|
} else {
|
|
return 4
|
|
}
|
|
})(),
|
|
reuseWorker: true,
|
|
wasi: __wasi,
|
|
onCreateWorker() {
|
|
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
env: process.env,
|
|
})
|
|
worker.onmessage = ({ data }) => {
|
|
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
}
|
|
|
|
// The main thread of Node.js waits for all the active handles before exiting.
|
|
// But Rust threads are never waited without `thread::join`.
|
|
// So here we hack the code of Node.js to prevent the workers from being referenced (active).
|
|
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
{
|
|
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
s.toString().includes("kPublicPort")
|
|
);
|
|
if (kPublicPort) {
|
|
worker[kPublicPort].ref = () => {};
|
|
}
|
|
|
|
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
s.toString().includes("kHandle")
|
|
);
|
|
if (kHandle) {
|
|
worker[kHandle].ref = () => {};
|
|
}
|
|
|
|
worker.unref();
|
|
}
|
|
return worker
|
|
},
|
|
overwriteImports(importObject) {
|
|
importObject.env = {
|
|
...importObject.env,
|
|
...importObject.napi,
|
|
...importObject.emnapi,
|
|
memory: __sharedMemory,
|
|
}
|
|
return importObject
|
|
},
|
|
beforeInit({ instance }) {
|
|
for (const name of Object.keys(instance.exports)) {
|
|
if (name.startsWith('__napi_register__')) {
|
|
instance.exports[name]()
|
|
}
|
|
}
|
|
},
|
|
})
|
|
module.exports = __napiModule.exports
|
|
module.exports.Workspace = __napiModule.exports.Workspace
|
|
module.exports.ZenDecision = __napiModule.exports.ZenDecision
|
|
module.exports.ZenDecisionContent = __napiModule.exports.ZenDecisionContent
|
|
module.exports.ZenEngine = __napiModule.exports.ZenEngine
|
|
module.exports.ZenEngineHandlerRequest = __napiModule.exports.ZenEngineHandlerRequest
|
|
module.exports.evaluateExpression = __napiModule.exports.evaluateExpression
|
|
module.exports.evaluateExpressionSync = __napiModule.exports.evaluateExpressionSync
|
|
module.exports.evaluateUnaryExpression = __napiModule.exports.evaluateUnaryExpression
|
|
module.exports.evaluateUnaryExpressionSync = __napiModule.exports.evaluateUnaryExpressionSync
|
|
module.exports.overrideConfig = __napiModule.exports.overrideConfig
|
|
module.exports.renderTemplate = __napiModule.exports.renderTemplate
|
|
module.exports.renderTemplateSync = __napiModule.exports.renderTemplateSync
|
|
module.exports.slotBatch = __napiModule.exports.slotBatch
|