@type-bridge/node 1.5.5 → 1.5.7
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 +63 -6
- package/dist/attribute.d.ts +22 -16
- package/dist/attribute.js +6 -0
- package/dist/flags.d.ts +46 -6
- package/dist/flags.js +33 -2
- package/dist/index.d.ts +33 -1
- package/dist/index.js +7 -2
- package/dist/model.d.ts +91 -10
- package/dist/model.js +165 -16
- package/dist/native.d.ts +106 -2
- package/dist/typed/index.d.ts +4 -0
- package/dist/typed/index.js +11 -0
- package/dist/typed/page.d.ts +13 -0
- package/dist/typed/page.js +35 -0
- package/dist/typed/query.d.ts +96 -0
- package/dist/typed/query.js +211 -0
- package/dist/typed/references.d.ts +192 -0
- package/dist/typed/references.js +363 -0
- package/dist/typed/results.d.ts +18 -0
- package/dist/typed/results.js +566 -0
- package/dist/typed/runtime-handles.d.ts +11 -0
- package/dist/typed/runtime-handles.js +33 -0
- package/dist/typed/session.d.ts +33 -0
- package/dist/typed/session.js +171 -0
- package/package.json +11 -3
- package/type_bridge_node.darwin-arm64.node +0 -0
- package/type_bridge_node.darwin-x64.node +0 -0
- package/type_bridge_node.linux-arm64-gnu.node +0 -0
- package/type_bridge_node.linux-x64-gnu.node +0 -0
- package/type_bridge_node.win32-arm64-msvc.node +0 -0
- package/type_bridge_node.win32-x64-msvc.node +0 -0
- package/dist/type-bridge-node-1.5.5.tgz +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuerySession = void 0;
|
|
4
|
+
exports.diagnosticQuerySession = diagnosticQuerySession;
|
|
5
|
+
exports.nativeSessionHandle = nativeSessionHandle;
|
|
6
|
+
exports.registeredModelConstructors = registeredModelConstructors;
|
|
7
|
+
const model_js_1 = require("../model.js");
|
|
8
|
+
const native_js_1 = require("../native.js");
|
|
9
|
+
const runtime_handles_js_1 = require("./runtime-handles.js");
|
|
10
|
+
const query_js_1 = require("./query.js");
|
|
11
|
+
const references_js_1 = require("./references.js");
|
|
12
|
+
const querySessionStates = new WeakMap();
|
|
13
|
+
const diagnosticQuerySessionToken = Symbol("type-bridge.diagnostic-query-session");
|
|
14
|
+
/**
|
|
15
|
+
* Owner of one native reference-construction session.
|
|
16
|
+
*
|
|
17
|
+
* Models are registered lazily from their canonical descriptors. Repeated
|
|
18
|
+
* calls for the same model deliberately return distinct native variables.
|
|
19
|
+
*/
|
|
20
|
+
class QuerySession {
|
|
21
|
+
#registered = new WeakSet();
|
|
22
|
+
#registering = new WeakSet();
|
|
23
|
+
constructor(connection) {
|
|
24
|
+
if (connection !== diagnosticQuerySessionToken &&
|
|
25
|
+
!(0, runtime_handles_js_1.isRegisteredRustConnection)(connection)) {
|
|
26
|
+
throw new TypeError("QuerySession requires a RustDatabase or RustTransactionContext");
|
|
27
|
+
}
|
|
28
|
+
const native = (0, native_js_1.loadNative)();
|
|
29
|
+
const registry = new native.NodeDescriptorRegistry();
|
|
30
|
+
querySessionStates.set(this, {
|
|
31
|
+
registry,
|
|
32
|
+
session: new native.NodeMatchSessionHandle(registry),
|
|
33
|
+
connection: connection === diagnosticQuerySessionToken ? undefined : connection,
|
|
34
|
+
models: new Map(),
|
|
35
|
+
knownModels: new Set(),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Register concrete constructors that JavaScript cannot discover through
|
|
40
|
+
* reverse class reflection. This is session-local metadata only; it does not
|
|
41
|
+
* create a query binding. Register subtype and relation-player descendants
|
|
42
|
+
* here before selecting a declared base with `"subtypes"`.
|
|
43
|
+
*/
|
|
44
|
+
registerModels(...models) {
|
|
45
|
+
const state = querySessionState(this);
|
|
46
|
+
for (const model of models) {
|
|
47
|
+
this.#requireConstructorAvailable(model);
|
|
48
|
+
}
|
|
49
|
+
for (const model of models) {
|
|
50
|
+
state.knownModels.add(model);
|
|
51
|
+
}
|
|
52
|
+
for (const model of models) {
|
|
53
|
+
this.#register(model);
|
|
54
|
+
}
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
var(model, matchMode = "exact") {
|
|
58
|
+
querySessionState(this).knownModels.add(model);
|
|
59
|
+
this.#register(model);
|
|
60
|
+
if (matchMode === "subtypes") {
|
|
61
|
+
const state = querySessionState(this);
|
|
62
|
+
for (const descendant of (0, model_js_1.modelConstructorDependencies)(model, true, (candidate) => state.knownModels.has(candidate))) {
|
|
63
|
+
this.#register(descendant);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const session = querySessionState(this).session;
|
|
67
|
+
const modelTypeName = model.typeName;
|
|
68
|
+
const handle = (0, references_js_1.nativeCall)(() => matchMode === "exact"
|
|
69
|
+
? session.exact(modelTypeName)
|
|
70
|
+
: session.subtypes(modelTypeName));
|
|
71
|
+
return (0, references_js_1.createBoundVar)(model, modelTypeName, handle);
|
|
72
|
+
}
|
|
73
|
+
query(...selections) {
|
|
74
|
+
requireSelectionArity(selections.length);
|
|
75
|
+
const state = querySessionState(this);
|
|
76
|
+
const shape = (0, references_js_1.nativeCall)(() => state.session.positional(selections.map(references_js_1.nativeSelectionHandle)));
|
|
77
|
+
const handle = (0, references_js_1.nativeCall)(() => state.session.query(shape));
|
|
78
|
+
return (0, query_js_1.createQuery)(handle, {
|
|
79
|
+
registry: state.registry,
|
|
80
|
+
connection: state.connection,
|
|
81
|
+
models: state.models,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
queryNamed(selections) {
|
|
85
|
+
const entries = Object.entries(selections);
|
|
86
|
+
requireSelectionArity(entries.length);
|
|
87
|
+
const state = querySessionState(this);
|
|
88
|
+
const shape = (0, references_js_1.nativeCall)(() => state.session.named(entries.map(([name]) => name), entries.map(([, selection]) => (0, references_js_1.nativeSelectionHandle)(selection))));
|
|
89
|
+
const handle = (0, references_js_1.nativeCall)(() => state.session.query(shape));
|
|
90
|
+
return (0, query_js_1.createQuery)(handle, {
|
|
91
|
+
registry: state.registry,
|
|
92
|
+
connection: state.connection,
|
|
93
|
+
models: state.models,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
#register(model) {
|
|
97
|
+
this.#requireConstructorAvailable(model);
|
|
98
|
+
if (this.#registered.has(model)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (this.#registering.has(model)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.#registering.add(model);
|
|
105
|
+
try {
|
|
106
|
+
const state = querySessionState(this);
|
|
107
|
+
state.knownModels.add(model);
|
|
108
|
+
for (const dependency of (0, model_js_1.modelConstructorDependencies)(model, false, (candidate) => state.knownModels.has(candidate))) {
|
|
109
|
+
this.#register(dependency);
|
|
110
|
+
}
|
|
111
|
+
const descriptor = model.descriptor();
|
|
112
|
+
const encoded = JSON.stringify(descriptor);
|
|
113
|
+
const registry = querySessionState(this).registry;
|
|
114
|
+
(0, references_js_1.nativeCall)(() => {
|
|
115
|
+
if (isRelationDescriptor(descriptor)) {
|
|
116
|
+
registry.registerRelationJson(encoded);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
registry.registerEntityJson(encoded);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
querySessionState(this).models.set(model.typeName, model);
|
|
123
|
+
this.#registered.add(model);
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
this.#registering.delete(model);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
#requireConstructorAvailable(model) {
|
|
130
|
+
const existing = querySessionState(this).models.get(model.typeName);
|
|
131
|
+
if (existing !== undefined && existing !== model) {
|
|
132
|
+
throw new references_js_1.TypedMatchError("invalid_plan", "model_constructor_conflict", `type '${model.typeName}' already has a different exact model constructor in this query session`, Object.freeze([]), Object.freeze({}));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.QuerySession = QuerySession;
|
|
137
|
+
/** @internal Construct a source-test session that can exercise planning without execution. */
|
|
138
|
+
function diagnosticQuerySession() {
|
|
139
|
+
const DiagnosticQuerySession = QuerySession;
|
|
140
|
+
return new DiagnosticQuerySession(diagnosticQuerySessionToken);
|
|
141
|
+
}
|
|
142
|
+
function querySessionState(session) {
|
|
143
|
+
const state = querySessionStates.get(session);
|
|
144
|
+
if (state === undefined) {
|
|
145
|
+
throw new TypeError("QuerySession was not constructed by this package");
|
|
146
|
+
}
|
|
147
|
+
return state;
|
|
148
|
+
}
|
|
149
|
+
/** @internal Extract the opaque native session for the future Query facade. */
|
|
150
|
+
function nativeSessionHandle(session) {
|
|
151
|
+
return querySessionState(session).session;
|
|
152
|
+
}
|
|
153
|
+
/** @internal Inspect exact constructor registration in focused binding tests. */
|
|
154
|
+
function registeredModelConstructors(session) {
|
|
155
|
+
return querySessionState(session).models;
|
|
156
|
+
}
|
|
157
|
+
function isRelationDescriptor(descriptor) {
|
|
158
|
+
return "roles" in descriptor;
|
|
159
|
+
}
|
|
160
|
+
function requireSelectionArity(actual) {
|
|
161
|
+
if (actual === 0) {
|
|
162
|
+
throw new references_js_1.TypedMatchError("invalid_plan", "empty_output", "typed queries must select at least one output binding", Object.freeze([{ kind: "output" }]), Object.freeze({}));
|
|
163
|
+
}
|
|
164
|
+
if (actual > 16) {
|
|
165
|
+
throw new references_js_1.TypedMatchError("invalid_plan", "selection_cap_exceeded", "selected output exceeds the canonical sixteen-slot ceiling", Object.freeze([{ kind: "output" }]), Object.freeze({
|
|
166
|
+
limit: Object.freeze({ kind: "text", value: "selected_slots" }),
|
|
167
|
+
actual: Object.freeze({ kind: "unsigned", value: actual }),
|
|
168
|
+
maximum: Object.freeze({ kind: "unsigned", value: 16 }),
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@type-bridge/node",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "Node.js NAPI facade for the type-bridge Rust ORM runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"require": "./dist/index.js",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./typed": {
|
|
15
|
+
"types": "./dist/typed/index.d.ts",
|
|
16
|
+
"require": "./dist/typed/index.js",
|
|
17
|
+
"default": "./dist/typed/index.js"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"files": [
|
|
@@ -21,7 +26,8 @@
|
|
|
21
26
|
"build": "npm run build:native && npm run build:types",
|
|
22
27
|
"prepublishOnly": "npm run build",
|
|
23
28
|
"build:native": "node scripts/build-native.js",
|
|
24
|
-
"
|
|
29
|
+
"clean:types": "node scripts/clean-types.js",
|
|
30
|
+
"build:types": "npm run clean:types && tsc -p tsconfig.json",
|
|
25
31
|
"build:typed-integration": "tsc -p tsconfig.typed-integration.json",
|
|
26
32
|
"build:parity-reader": "tsc -p tsconfig.parity.json",
|
|
27
33
|
"build:generator-parity": "tsc -p tsconfig.generator-parity.json",
|
|
@@ -30,8 +36,10 @@
|
|
|
30
36
|
"dts:baseline": "node tests/dts-parity.cjs --update",
|
|
31
37
|
"test:dts": "node --test tests/dts-parity.test.cjs",
|
|
32
38
|
"smoke:package": "node tests/package-smoke.cjs",
|
|
33
|
-
"
|
|
39
|
+
"smoke:legacy-package": "node tests/compat/legacy-package/run.cjs",
|
|
40
|
+
"test:unit": "tsc -p tsconfig.unit.json && node scripts/run-unit.js",
|
|
34
41
|
"typecheck": "tsc --noEmit",
|
|
42
|
+
"typecheck:query-contract": "tsc -p tests/compat/typed-query-contract/tsconfig.json --noEmit",
|
|
35
43
|
"typecheck:integration": "tsc -p tsconfig.integration.json",
|
|
36
44
|
"test:typed-integration": "npm run build:typed-integration && node --test ../../../tmp/node-typed-integration/tests/typed-integration/*.test.js ../../../tmp/node-typed-integration/tests/integration/typed/*.test.js",
|
|
37
45
|
"test:integration": "node scripts/run-integration.js"
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|