@type-bridge/node 1.5.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.
- package/README.md +102 -0
- package/dist/attribute.d.ts +102 -0
- package/dist/attribute.js +176 -0
- package/dist/codec.d.ts +36 -0
- package/dist/codec.js +274 -0
- package/dist/flags.d.ts +67 -0
- package/dist/flags.js +123 -0
- package/dist/generator/cardinality.d.ts +15 -0
- package/dist/generator/cardinality.js +28 -0
- package/dist/generator/index.d.ts +44 -0
- package/dist/generator/index.js +64 -0
- package/dist/generator/naming.d.ts +64 -0
- package/dist/generator/naming.js +69 -0
- package/dist/generator/renderAttributes.d.ts +22 -0
- package/dist/generator/renderAttributes.js +153 -0
- package/dist/generator/renderEntities.d.ts +39 -0
- package/dist/generator/renderEntities.js +273 -0
- package/dist/generator/renderPackage.d.ts +22 -0
- package/dist/generator/renderPackage.js +33 -0
- package/dist/generator/renderRelations.d.ts +36 -0
- package/dist/generator/renderRelations.js +395 -0
- package/dist/iid.d.ts +5 -0
- package/dist/iid.js +20 -0
- package/dist/index.d.ts +469 -0
- package/dist/index.js +451 -0
- package/dist/manager.d.ts +51 -0
- package/dist/manager.js +282 -0
- package/dist/model.d.ts +261 -0
- package/dist/model.js +481 -0
- package/dist/native.d.ts +14 -0
- package/dist/native.js +125 -0
- package/dist/parser.d.ts +106 -0
- package/dist/parser.js +20 -0
- package/dist/query.d.ts +109 -0
- package/dist/query.js +240 -0
- package/dist/type-bridge-node-1.5.0.tgz +0 -0
- package/package.json +53 -0
- package/type_bridge_node.linux-x64-gnu.node +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RustDynamicEntityManager = exports.RustTransactionContext = exports.RustDatabase = exports.Marshalling = exports.DescriptorRegistry = exports.loadNative = exports.parseSchema = exports.relationManagerFor = exports.entityManagerFor = exports.buildRolePlayers = exports.TypedRelationManager = exports.TypedEntityManager = exports.runtimeAttributeValueFromUnknown = exports.plainToAttribute = exports.lowerFilters = exports.lowerAttributeValue = exports.lowerAttributes = exports.keyAttributeDescriptor = exports.hydrateAttributes = exports.hydrateAttributeEntries = exports.attributeToPlain = exports.TypedCodecError = exports.role = exports.field = exports.RoleSpec = exports.Relation = exports.ListFieldSpec = exports.FieldSpec = exports.Entity = exports.resolveFlags = exports.formatTypeName = exports.Unique = exports.TypeNameCase = exports.TypeFlags = exports.Key = exports.Flag = exports.Card = exports.AttributeFlags = exports.agg = exports.TypedQueryError = exports.TypedQuery = exports.TypedGroupByQuery = exports.SortExpr = exports.QueryExpr = exports.NotExpr = exports.ComparisonExpr = exports.BooleanExpr = exports.AggregateSpec = exports.attr = exports.Attribute = void 0;
|
|
4
|
+
exports.generateModels = exports.RustDynamicRelationManager = void 0;
|
|
5
|
+
exports.string = string;
|
|
6
|
+
exports.long = long;
|
|
7
|
+
exports.longFromNumberUnsafe = longFromNumberUnsafe;
|
|
8
|
+
exports.double = double;
|
|
9
|
+
exports.boolean = boolean;
|
|
10
|
+
exports.date = date;
|
|
11
|
+
exports.datetime = datetime;
|
|
12
|
+
exports.datetimetz = datetimetz;
|
|
13
|
+
exports.decimal = decimal;
|
|
14
|
+
exports.duration = duration;
|
|
15
|
+
exports.ensureDatabase = ensureDatabase;
|
|
16
|
+
exports.generateDefineBlock = generateDefineBlock;
|
|
17
|
+
const native_js_1 = require("./native.js");
|
|
18
|
+
Object.defineProperty(exports, "loadNative", { enumerable: true, get: function () { return native_js_1.loadNative; } });
|
|
19
|
+
const ATTRIBUTE_SCHEMA_METADATA = Symbol.for("@type-bridge/node.attributeSchemaMetadata");
|
|
20
|
+
var attribute_js_1 = require("./attribute.js");
|
|
21
|
+
Object.defineProperty(exports, "Attribute", { enumerable: true, get: function () { return attribute_js_1.Attribute; } });
|
|
22
|
+
Object.defineProperty(exports, "attr", { enumerable: true, get: function () { return attribute_js_1.attr; } });
|
|
23
|
+
var query_js_1 = require("./query.js");
|
|
24
|
+
Object.defineProperty(exports, "AggregateSpec", { enumerable: true, get: function () { return query_js_1.AggregateSpec; } });
|
|
25
|
+
Object.defineProperty(exports, "BooleanExpr", { enumerable: true, get: function () { return query_js_1.BooleanExpr; } });
|
|
26
|
+
Object.defineProperty(exports, "ComparisonExpr", { enumerable: true, get: function () { return query_js_1.ComparisonExpr; } });
|
|
27
|
+
Object.defineProperty(exports, "NotExpr", { enumerable: true, get: function () { return query_js_1.NotExpr; } });
|
|
28
|
+
Object.defineProperty(exports, "QueryExpr", { enumerable: true, get: function () { return query_js_1.QueryExpr; } });
|
|
29
|
+
Object.defineProperty(exports, "SortExpr", { enumerable: true, get: function () { return query_js_1.SortExpr; } });
|
|
30
|
+
Object.defineProperty(exports, "TypedGroupByQuery", { enumerable: true, get: function () { return query_js_1.TypedGroupByQuery; } });
|
|
31
|
+
Object.defineProperty(exports, "TypedQuery", { enumerable: true, get: function () { return query_js_1.TypedQuery; } });
|
|
32
|
+
Object.defineProperty(exports, "TypedQueryError", { enumerable: true, get: function () { return query_js_1.TypedQueryError; } });
|
|
33
|
+
Object.defineProperty(exports, "agg", { enumerable: true, get: function () { return query_js_1.agg; } });
|
|
34
|
+
var flags_js_1 = require("./flags.js");
|
|
35
|
+
Object.defineProperty(exports, "AttributeFlags", { enumerable: true, get: function () { return flags_js_1.AttributeFlags; } });
|
|
36
|
+
Object.defineProperty(exports, "Card", { enumerable: true, get: function () { return flags_js_1.Card; } });
|
|
37
|
+
Object.defineProperty(exports, "Flag", { enumerable: true, get: function () { return flags_js_1.Flag; } });
|
|
38
|
+
Object.defineProperty(exports, "Key", { enumerable: true, get: function () { return flags_js_1.Key; } });
|
|
39
|
+
Object.defineProperty(exports, "TypeFlags", { enumerable: true, get: function () { return flags_js_1.TypeFlags; } });
|
|
40
|
+
Object.defineProperty(exports, "TypeNameCase", { enumerable: true, get: function () { return flags_js_1.TypeNameCase; } });
|
|
41
|
+
Object.defineProperty(exports, "Unique", { enumerable: true, get: function () { return flags_js_1.Unique; } });
|
|
42
|
+
Object.defineProperty(exports, "formatTypeName", { enumerable: true, get: function () { return flags_js_1.formatTypeName; } });
|
|
43
|
+
Object.defineProperty(exports, "resolveFlags", { enumerable: true, get: function () { return flags_js_1.resolveFlags; } });
|
|
44
|
+
var model_js_1 = require("./model.js");
|
|
45
|
+
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return model_js_1.Entity; } });
|
|
46
|
+
Object.defineProperty(exports, "FieldSpec", { enumerable: true, get: function () { return model_js_1.FieldSpec; } });
|
|
47
|
+
Object.defineProperty(exports, "ListFieldSpec", { enumerable: true, get: function () { return model_js_1.ListFieldSpec; } });
|
|
48
|
+
Object.defineProperty(exports, "Relation", { enumerable: true, get: function () { return model_js_1.Relation; } });
|
|
49
|
+
Object.defineProperty(exports, "RoleSpec", { enumerable: true, get: function () { return model_js_1.RoleSpec; } });
|
|
50
|
+
Object.defineProperty(exports, "field", { enumerable: true, get: function () { return model_js_1.field; } });
|
|
51
|
+
Object.defineProperty(exports, "role", { enumerable: true, get: function () { return model_js_1.role; } });
|
|
52
|
+
var codec_js_1 = require("./codec.js");
|
|
53
|
+
Object.defineProperty(exports, "TypedCodecError", { enumerable: true, get: function () { return codec_js_1.TypedCodecError; } });
|
|
54
|
+
Object.defineProperty(exports, "attributeToPlain", { enumerable: true, get: function () { return codec_js_1.attributeToPlain; } });
|
|
55
|
+
Object.defineProperty(exports, "hydrateAttributeEntries", { enumerable: true, get: function () { return codec_js_1.hydrateAttributeEntries; } });
|
|
56
|
+
Object.defineProperty(exports, "hydrateAttributes", { enumerable: true, get: function () { return codec_js_1.hydrateAttributes; } });
|
|
57
|
+
Object.defineProperty(exports, "keyAttributeDescriptor", { enumerable: true, get: function () { return codec_js_1.keyAttributeDescriptor; } });
|
|
58
|
+
Object.defineProperty(exports, "lowerAttributes", { enumerable: true, get: function () { return codec_js_1.lowerAttributes; } });
|
|
59
|
+
Object.defineProperty(exports, "lowerAttributeValue", { enumerable: true, get: function () { return codec_js_1.lowerAttributeValue; } });
|
|
60
|
+
Object.defineProperty(exports, "lowerFilters", { enumerable: true, get: function () { return codec_js_1.lowerFilters; } });
|
|
61
|
+
Object.defineProperty(exports, "plainToAttribute", { enumerable: true, get: function () { return codec_js_1.plainToAttribute; } });
|
|
62
|
+
Object.defineProperty(exports, "runtimeAttributeValueFromUnknown", { enumerable: true, get: function () { return codec_js_1.runtimeAttributeValueFromUnknown; } });
|
|
63
|
+
var manager_js_1 = require("./manager.js");
|
|
64
|
+
Object.defineProperty(exports, "TypedEntityManager", { enumerable: true, get: function () { return manager_js_1.TypedEntityManager; } });
|
|
65
|
+
Object.defineProperty(exports, "TypedRelationManager", { enumerable: true, get: function () { return manager_js_1.TypedRelationManager; } });
|
|
66
|
+
Object.defineProperty(exports, "buildRolePlayers", { enumerable: true, get: function () { return manager_js_1.buildRolePlayers; } });
|
|
67
|
+
Object.defineProperty(exports, "entityManagerFor", { enumerable: true, get: function () { return manager_js_1.entityManagerFor; } });
|
|
68
|
+
Object.defineProperty(exports, "relationManagerFor", { enumerable: true, get: function () { return manager_js_1.relationManagerFor; } });
|
|
69
|
+
var parser_js_1 = require("./parser.js");
|
|
70
|
+
Object.defineProperty(exports, "parseSchema", { enumerable: true, get: function () { return parser_js_1.parseSchema; } });
|
|
71
|
+
function string(value) {
|
|
72
|
+
return { value_type: "string", value };
|
|
73
|
+
}
|
|
74
|
+
function long(value) {
|
|
75
|
+
// Runtime guard for JavaScript callers (the static `bigint` type is erased):
|
|
76
|
+
// a non-bigint would silently stringify to a wrong wire value otherwise.
|
|
77
|
+
if (typeof value !== "bigint") {
|
|
78
|
+
throw new TypeError("long requires a bigint; use longFromNumberUnsafe for explicit number conversion");
|
|
79
|
+
}
|
|
80
|
+
return { value_type: "long", value: value.toString() };
|
|
81
|
+
}
|
|
82
|
+
function longFromNumberUnsafe(value) {
|
|
83
|
+
if (!Number.isFinite(value) || !Number.isInteger(value)) {
|
|
84
|
+
throw new TypeError("longFromNumberUnsafe requires a finite integer number");
|
|
85
|
+
}
|
|
86
|
+
return { value_type: "long", value: value.toString() };
|
|
87
|
+
}
|
|
88
|
+
function double(value) {
|
|
89
|
+
if (!Number.isFinite(value)) {
|
|
90
|
+
throw new TypeError("double requires a finite number");
|
|
91
|
+
}
|
|
92
|
+
return { value_type: "double", value };
|
|
93
|
+
}
|
|
94
|
+
function boolean(value) {
|
|
95
|
+
return { value_type: "boolean", value };
|
|
96
|
+
}
|
|
97
|
+
function date(value) {
|
|
98
|
+
return { value_type: "date", value };
|
|
99
|
+
}
|
|
100
|
+
function datetime(value) {
|
|
101
|
+
return { value_type: "datetime", value };
|
|
102
|
+
}
|
|
103
|
+
function datetimetz(value) {
|
|
104
|
+
return { value_type: "datetime-tz", value };
|
|
105
|
+
}
|
|
106
|
+
function decimal(value) {
|
|
107
|
+
return { value_type: "decimal", value };
|
|
108
|
+
}
|
|
109
|
+
function duration(value) {
|
|
110
|
+
return { value_type: "duration", value };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Ensure the named TypeDB database exists, creating it if absent.
|
|
114
|
+
*
|
|
115
|
+
* Fails hard when TypeDB is unreachable — callers should let the error
|
|
116
|
+
* propagate so that a missing server shows up as a clear failure, not a
|
|
117
|
+
* silent skip.
|
|
118
|
+
*/
|
|
119
|
+
function ensureDatabase(address, database, options) {
|
|
120
|
+
(0, native_js_1.loadNative)().ensureRustDatabase(address, database, options?.username ?? null, options?.password ?? null, options?.httpPort ?? null);
|
|
121
|
+
}
|
|
122
|
+
function generateDefineBlock(info) {
|
|
123
|
+
return (0, native_js_1.loadNative)().generateDefineBlockJson(JSON.stringify(info));
|
|
124
|
+
}
|
|
125
|
+
class DescriptorRegistry {
|
|
126
|
+
#native;
|
|
127
|
+
#attributeSchemas = new Map();
|
|
128
|
+
constructor(nativeRegistry) {
|
|
129
|
+
this.#native = nativeRegistry ?? new ((0, native_js_1.loadNative)().NodeDescriptorRegistry)();
|
|
130
|
+
}
|
|
131
|
+
registerEntity(descriptor) {
|
|
132
|
+
this.#rememberAttributeSchemas(descriptor);
|
|
133
|
+
return parseJson(this.#native.registerEntityJson(JSON.stringify(descriptor)));
|
|
134
|
+
}
|
|
135
|
+
registerRelation(descriptor) {
|
|
136
|
+
this.#rememberAttributeSchemas(descriptor);
|
|
137
|
+
return parseJson(this.#native.registerRelationJson(JSON.stringify(descriptor)));
|
|
138
|
+
}
|
|
139
|
+
entity(typeName) {
|
|
140
|
+
return parseJson(this.#native.entityJson(typeName));
|
|
141
|
+
}
|
|
142
|
+
relation(typeName) {
|
|
143
|
+
return parseJson(this.#native.relationJson(typeName));
|
|
144
|
+
}
|
|
145
|
+
snapshot() {
|
|
146
|
+
return parseJson(this.#native.snapshotJson());
|
|
147
|
+
}
|
|
148
|
+
schemaInfo() {
|
|
149
|
+
// Rust from_descriptors builds plays_cardinalities overlays and nulls foreign
|
|
150
|
+
// parent_types; the Python attributes-section merge remains the only Python-side
|
|
151
|
+
// projection.
|
|
152
|
+
const info = parseJson(this.#native.schemaInfoJson());
|
|
153
|
+
for (const [attrName, entry] of this.#attributeSchemas) {
|
|
154
|
+
info.attributes[attrName] = {
|
|
155
|
+
...(info.attributes[attrName] ?? { attr_name: attrName, value_type: entry.value_type }),
|
|
156
|
+
...copyAttributeSchemaEntry(entry),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return info;
|
|
160
|
+
}
|
|
161
|
+
#rememberAttributeSchemas(descriptor) {
|
|
162
|
+
for (const entry of descriptorAttributeSchemaMetadata(descriptor)) {
|
|
163
|
+
this.#attributeSchemas.set(entry.attr_name, copyAttributeSchemaEntry(entry));
|
|
164
|
+
}
|
|
165
|
+
for (const attribute of descriptor.owned_attributes) {
|
|
166
|
+
const entry = ownedAttributeSchemaEntry(attribute);
|
|
167
|
+
if (entry !== null) {
|
|
168
|
+
this.#attributeSchemas.set(entry.attr_name, entry);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.DescriptorRegistry = DescriptorRegistry;
|
|
174
|
+
function descriptorAttributeSchemaMetadata(descriptor) {
|
|
175
|
+
const metadata = descriptor[ATTRIBUTE_SCHEMA_METADATA];
|
|
176
|
+
if (metadata === null || typeof metadata !== "object") {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
return Object.values(metadata).map(copyAttributeSchemaEntry);
|
|
180
|
+
}
|
|
181
|
+
function ownedAttributeSchemaEntry(attribute) {
|
|
182
|
+
if (!hasAttributeTypeMetadata(attribute)) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const entry = {
|
|
186
|
+
attr_name: attribute.attr_name,
|
|
187
|
+
value_type: attribute.value_type,
|
|
188
|
+
};
|
|
189
|
+
if (attribute.parent_type !== undefined)
|
|
190
|
+
entry.parent_type = attribute.parent_type;
|
|
191
|
+
if (attribute.is_abstract !== undefined)
|
|
192
|
+
entry.is_abstract = attribute.is_abstract;
|
|
193
|
+
if (attribute.is_independent !== undefined)
|
|
194
|
+
entry.is_independent = attribute.is_independent;
|
|
195
|
+
if (attribute.regex !== undefined)
|
|
196
|
+
entry.regex = attribute.regex;
|
|
197
|
+
if (attribute.allowed_values !== undefined) {
|
|
198
|
+
entry.allowed_values =
|
|
199
|
+
attribute.allowed_values == null ? null : [...attribute.allowed_values];
|
|
200
|
+
}
|
|
201
|
+
if (attribute.range !== undefined) {
|
|
202
|
+
entry.range = attribute.range == null ? null : [attribute.range[0], attribute.range[1]];
|
|
203
|
+
}
|
|
204
|
+
return entry;
|
|
205
|
+
}
|
|
206
|
+
function hasAttributeTypeMetadata(attribute) {
|
|
207
|
+
return (attribute.parent_type !== undefined ||
|
|
208
|
+
attribute.is_abstract !== undefined ||
|
|
209
|
+
attribute.is_independent !== undefined ||
|
|
210
|
+
attribute.regex !== undefined ||
|
|
211
|
+
attribute.allowed_values !== undefined ||
|
|
212
|
+
attribute.range !== undefined);
|
|
213
|
+
}
|
|
214
|
+
function copyAttributeSchemaEntry(entry) {
|
|
215
|
+
const copy = { ...entry };
|
|
216
|
+
if (entry.allowed_values !== undefined) {
|
|
217
|
+
copy.allowed_values = entry.allowed_values === null ? null : [...entry.allowed_values];
|
|
218
|
+
}
|
|
219
|
+
if (entry.range !== undefined) {
|
|
220
|
+
copy.range = entry.range === null ? null : [entry.range[0], entry.range[1]];
|
|
221
|
+
}
|
|
222
|
+
return copy;
|
|
223
|
+
}
|
|
224
|
+
class Marshalling {
|
|
225
|
+
#native;
|
|
226
|
+
constructor(nativeMarshalling) {
|
|
227
|
+
this.#native = nativeMarshalling ?? (0, native_js_1.loadNative)();
|
|
228
|
+
}
|
|
229
|
+
attributeValue(value) {
|
|
230
|
+
return parseJson(this.#native.normalizeAttributeValueJson(JSON.stringify(value)));
|
|
231
|
+
}
|
|
232
|
+
entityAttributes(descriptor, attributes) {
|
|
233
|
+
return parseJson(this.#native.normalizeEntityAttributesJson(JSON.stringify(descriptor), JSON.stringify(attributes)));
|
|
234
|
+
}
|
|
235
|
+
relationAttributes(descriptor, attributes) {
|
|
236
|
+
return parseJson(this.#native.normalizeRelationAttributesJson(JSON.stringify(descriptor), JSON.stringify(attributes)));
|
|
237
|
+
}
|
|
238
|
+
filters(descriptor, filters) {
|
|
239
|
+
return parseJson(this.#native.normalizeFiltersJson(JSON.stringify(descriptor), JSON.stringify(filters)));
|
|
240
|
+
}
|
|
241
|
+
relationFilters(descriptor, filters) {
|
|
242
|
+
return parseJson(this.#native.normalizeRelationFiltersJson(JSON.stringify(descriptor), JSON.stringify(filters)));
|
|
243
|
+
}
|
|
244
|
+
aggregates(descriptor, aggregates) {
|
|
245
|
+
return parseJson(this.#native.normalizeAggregatesJson(JSON.stringify(descriptor), JSON.stringify(aggregates)));
|
|
246
|
+
}
|
|
247
|
+
rolePlayers(descriptor, rolePlayers) {
|
|
248
|
+
return parseJson(this.#native.normalizeRolePlayersJson(JSON.stringify(descriptor), JSON.stringify(rolePlayers)));
|
|
249
|
+
}
|
|
250
|
+
relationWriteBatch(descriptor, batch) {
|
|
251
|
+
return parseJson(this.#native.normalizeRelationWriteBatchJson(JSON.stringify(descriptor), JSON.stringify(batch)));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.Marshalling = Marshalling;
|
|
255
|
+
class RustDatabase {
|
|
256
|
+
#native;
|
|
257
|
+
constructor(native) {
|
|
258
|
+
this.#native = native;
|
|
259
|
+
}
|
|
260
|
+
static connect(nativeOrAddress, addressOrDatabase, databaseOrOptions = {}, maybeOptions = {}) {
|
|
261
|
+
const parsed = parseConnectArguments(nativeOrAddress, addressOrDatabase, databaseOrOptions, maybeOptions);
|
|
262
|
+
return new RustDatabase(parsed.native.connectRustDatabase(parsed.address, parsed.database, parsed.options.username ?? null, parsed.options.password ?? null, parsed.options.httpPort ?? null));
|
|
263
|
+
}
|
|
264
|
+
isConnected() {
|
|
265
|
+
return this.#native.isConnected();
|
|
266
|
+
}
|
|
267
|
+
databaseName() {
|
|
268
|
+
return this.#native.databaseName();
|
|
269
|
+
}
|
|
270
|
+
transaction(transactionType = "read") {
|
|
271
|
+
return new RustTransactionContext(this.#native.transaction(transactionType));
|
|
272
|
+
}
|
|
273
|
+
entityManager(descriptor) {
|
|
274
|
+
return new RustDynamicEntityManager(this.#native.entityManagerJson(JSON.stringify(descriptor)));
|
|
275
|
+
}
|
|
276
|
+
relationManager(descriptor) {
|
|
277
|
+
return new RustDynamicRelationManager(this.#native.relationManagerJson(JSON.stringify(descriptor)));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
exports.RustDatabase = RustDatabase;
|
|
281
|
+
class RustTransactionContext {
|
|
282
|
+
#native;
|
|
283
|
+
constructor(native) {
|
|
284
|
+
this.#native = native;
|
|
285
|
+
}
|
|
286
|
+
query(query) {
|
|
287
|
+
return parseJson(this.#native.queryJson(query));
|
|
288
|
+
}
|
|
289
|
+
commit() {
|
|
290
|
+
this.#native.commit();
|
|
291
|
+
}
|
|
292
|
+
rollback() {
|
|
293
|
+
this.#native.rollback();
|
|
294
|
+
}
|
|
295
|
+
close() {
|
|
296
|
+
this.#native.close();
|
|
297
|
+
}
|
|
298
|
+
transactionType() {
|
|
299
|
+
return this.#native.transactionType();
|
|
300
|
+
}
|
|
301
|
+
entityManager(descriptor) {
|
|
302
|
+
return new RustDynamicEntityManager(this.#native.entityManagerJson(JSON.stringify(descriptor)));
|
|
303
|
+
}
|
|
304
|
+
relationManager(descriptor) {
|
|
305
|
+
return new RustDynamicRelationManager(this.#native.relationManagerJson(JSON.stringify(descriptor)));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
exports.RustTransactionContext = RustTransactionContext;
|
|
309
|
+
class RustDynamicEntityManager {
|
|
310
|
+
#native;
|
|
311
|
+
constructor(native) {
|
|
312
|
+
this.#native = native;
|
|
313
|
+
}
|
|
314
|
+
insert(attributes) {
|
|
315
|
+
return this.#native.insertJson(JSON.stringify(attributes));
|
|
316
|
+
}
|
|
317
|
+
insertMany(batch) {
|
|
318
|
+
return parseJson(this.#native.insertManyJson(JSON.stringify(batch)));
|
|
319
|
+
}
|
|
320
|
+
put(attributes) {
|
|
321
|
+
return this.#native.putJson(JSON.stringify(attributes));
|
|
322
|
+
}
|
|
323
|
+
putMany(batch) {
|
|
324
|
+
return parseJson(this.#native.putManyJson(JSON.stringify(batch)));
|
|
325
|
+
}
|
|
326
|
+
update(attributes, iid) {
|
|
327
|
+
this.#native.updateJson(JSON.stringify(attributes), iid ?? null);
|
|
328
|
+
}
|
|
329
|
+
get(filters) {
|
|
330
|
+
return parseJson(this.#native.getJson(optionalJson(filters)));
|
|
331
|
+
}
|
|
332
|
+
getByIid(iid) {
|
|
333
|
+
return parseJson(this.#native.getByIidJson(iid));
|
|
334
|
+
}
|
|
335
|
+
all() {
|
|
336
|
+
return parseJson(this.#native.allJson());
|
|
337
|
+
}
|
|
338
|
+
count(filters) {
|
|
339
|
+
return BigInt(this.#native.countJson(optionalJson(filters)));
|
|
340
|
+
}
|
|
341
|
+
aggregate(aggregates, filters) {
|
|
342
|
+
return parseJson(this.#native.aggregateJson(JSON.stringify(aggregates), optionalJson(filters)));
|
|
343
|
+
}
|
|
344
|
+
groupByAggregate(groupFields, aggregates, filters) {
|
|
345
|
+
return parseJson(this.#native.groupByAggregateJson(JSON.stringify(groupFields), JSON.stringify(aggregates), optionalJson(filters)));
|
|
346
|
+
}
|
|
347
|
+
query(spec) {
|
|
348
|
+
return parseJson(this.#native.queryJson(JSON.stringify(spec)));
|
|
349
|
+
}
|
|
350
|
+
queryCount(spec) {
|
|
351
|
+
return BigInt(this.#native.queryCountJson(JSON.stringify(spec)));
|
|
352
|
+
}
|
|
353
|
+
queryAggregate(spec, aggregates) {
|
|
354
|
+
return parseJson(this.#native.queryAggregateJson(JSON.stringify(spec), JSON.stringify(aggregates)));
|
|
355
|
+
}
|
|
356
|
+
queryGroupByAggregate(spec, groupFields, aggregates) {
|
|
357
|
+
return parseJson(this.#native.queryGroupByAggregateJson(JSON.stringify(spec), JSON.stringify(groupFields), JSON.stringify(aggregates)));
|
|
358
|
+
}
|
|
359
|
+
deleteByIid(iid) {
|
|
360
|
+
this.#native.deleteByIid(iid);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
exports.RustDynamicEntityManager = RustDynamicEntityManager;
|
|
364
|
+
class RustDynamicRelationManager {
|
|
365
|
+
#native;
|
|
366
|
+
constructor(native) {
|
|
367
|
+
this.#native = native;
|
|
368
|
+
}
|
|
369
|
+
insert(attributes, rolePlayers) {
|
|
370
|
+
return this.#native.insertJson(JSON.stringify(attributes), JSON.stringify(rolePlayers));
|
|
371
|
+
}
|
|
372
|
+
insertMany(batch) {
|
|
373
|
+
return parseJson(this.#native.insertManyJson(JSON.stringify(batch)));
|
|
374
|
+
}
|
|
375
|
+
put(attributes, rolePlayers) {
|
|
376
|
+
return this.#native.putJson(JSON.stringify(attributes), JSON.stringify(rolePlayers));
|
|
377
|
+
}
|
|
378
|
+
putMany(batch) {
|
|
379
|
+
return parseJson(this.#native.putManyJson(JSON.stringify(batch)));
|
|
380
|
+
}
|
|
381
|
+
update(attributes, rolePlayers, iid) {
|
|
382
|
+
this.#native.updateJson(JSON.stringify(attributes), JSON.stringify(rolePlayers), iid ?? null);
|
|
383
|
+
}
|
|
384
|
+
get(filters) {
|
|
385
|
+
return parseJson(this.#native.getJson(optionalJson(filters)));
|
|
386
|
+
}
|
|
387
|
+
getWithRolePlayers(filters, rolePlayers) {
|
|
388
|
+
return parseJson(this.#native.getWithRolePlayersJson(optionalJson(filters), optionalJson(rolePlayers)));
|
|
389
|
+
}
|
|
390
|
+
getByIid(iid) {
|
|
391
|
+
return parseJson(this.#native.getByIidJson(iid));
|
|
392
|
+
}
|
|
393
|
+
all() {
|
|
394
|
+
return parseJson(this.#native.allJson());
|
|
395
|
+
}
|
|
396
|
+
count(filters) {
|
|
397
|
+
return BigInt(this.#native.countJson(optionalJson(filters)));
|
|
398
|
+
}
|
|
399
|
+
aggregate(aggregates, filters) {
|
|
400
|
+
return parseJson(this.#native.aggregateJson(JSON.stringify(aggregates), optionalJson(filters)));
|
|
401
|
+
}
|
|
402
|
+
groupByAggregate(groupFields, aggregates, filters) {
|
|
403
|
+
return parseJson(this.#native.groupByAggregateJson(JSON.stringify(groupFields), JSON.stringify(aggregates), optionalJson(filters)));
|
|
404
|
+
}
|
|
405
|
+
query(spec) {
|
|
406
|
+
return parseJson(this.#native.queryJson(JSON.stringify(spec)));
|
|
407
|
+
}
|
|
408
|
+
queryCount(spec) {
|
|
409
|
+
return BigInt(this.#native.queryCountJson(JSON.stringify(spec)));
|
|
410
|
+
}
|
|
411
|
+
queryAggregate(spec, aggregates) {
|
|
412
|
+
return parseJson(this.#native.queryAggregateJson(JSON.stringify(spec), JSON.stringify(aggregates)));
|
|
413
|
+
}
|
|
414
|
+
queryGroupByAggregate(spec, groupFields, aggregates) {
|
|
415
|
+
return parseJson(this.#native.queryGroupByAggregateJson(JSON.stringify(spec), JSON.stringify(groupFields), JSON.stringify(aggregates)));
|
|
416
|
+
}
|
|
417
|
+
deleteByIid(iid) {
|
|
418
|
+
this.#native.deleteByIid(iid);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
exports.RustDynamicRelationManager = RustDynamicRelationManager;
|
|
422
|
+
function parseJson(value) {
|
|
423
|
+
return JSON.parse(value);
|
|
424
|
+
}
|
|
425
|
+
function optionalJson(value) {
|
|
426
|
+
return value == null ? null : JSON.stringify(value);
|
|
427
|
+
}
|
|
428
|
+
function parseConnectArguments(nativeOrAddress, addressOrDatabase, databaseOrOptions, maybeOptions) {
|
|
429
|
+
if (typeof nativeOrAddress === "string") {
|
|
430
|
+
return {
|
|
431
|
+
native: (0, native_js_1.loadNative)(),
|
|
432
|
+
address: nativeOrAddress,
|
|
433
|
+
database: addressOrDatabase,
|
|
434
|
+
options: databaseOrOptions ?? {},
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
if (typeof databaseOrOptions !== "string") {
|
|
438
|
+
throw new TypeError("RustDatabase.connect(native, address, database, options?) requires a database string");
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
native: nativeOrAddress,
|
|
442
|
+
address: addressOrDatabase,
|
|
443
|
+
database: databaseOrOptions,
|
|
444
|
+
options: maybeOptions ?? {},
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
// ---------------------------------------------------------------------------
|
|
448
|
+
// Generator — additive re-export
|
|
449
|
+
// ---------------------------------------------------------------------------
|
|
450
|
+
var index_js_1 = require("./generator/index.js");
|
|
451
|
+
Object.defineProperty(exports, "generateModels", { enumerable: true, get: function () { return index_js_1.generateModels; } });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type DynamicEntityRow, type DynamicRelationRow, type EntityDescriptor, type RelationDescriptor, type RolePlayerInput, type RustDatabase, type RustTransactionContext } from "./index.js";
|
|
2
|
+
import { TypedQuery } from "./query.js";
|
|
3
|
+
import { type Attribute } from "./attribute.js";
|
|
4
|
+
import { type IidBearing } from "./iid.js";
|
|
5
|
+
import type { EntitySchema, RelationSchema } from "./model.js";
|
|
6
|
+
export type ManagerConnection = RustDatabase | RustTransactionContext;
|
|
7
|
+
export type ExactFilters<T> = Partial<{
|
|
8
|
+
readonly [Key in keyof T as NonNullable<T[Key]> extends Attribute<unknown, string> ? Key : never]: NonNullable<T[Key]>;
|
|
9
|
+
}>;
|
|
10
|
+
type EntityConstructor<T extends IidBearing> = (new (values: Record<string, unknown>) => T) & {
|
|
11
|
+
readonly schema: EntitySchema;
|
|
12
|
+
descriptor(): EntityDescriptor;
|
|
13
|
+
};
|
|
14
|
+
type RelationConstructor<T extends IidBearing> = (new (values: Record<string, unknown>) => T) & {
|
|
15
|
+
readonly schema: RelationSchema;
|
|
16
|
+
descriptor(): RelationDescriptor;
|
|
17
|
+
};
|
|
18
|
+
export declare class TypedEntityManager<T extends IidBearing> {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(modelClass: EntityConstructor<T>, connection: ManagerConnection);
|
|
21
|
+
insert(instance: T): T;
|
|
22
|
+
insertMany(instances: readonly T[]): T[];
|
|
23
|
+
put(instance: T): T;
|
|
24
|
+
putMany(instances: readonly T[]): T[];
|
|
25
|
+
update(instance: T): T;
|
|
26
|
+
get(filters?: ExactFilters<T> | null): T[];
|
|
27
|
+
all(): T[];
|
|
28
|
+
getByIid(iid: string): T | null;
|
|
29
|
+
count(filters?: ExactFilters<T> | null): bigint;
|
|
30
|
+
query(): TypedQuery<T, DynamicEntityRow>;
|
|
31
|
+
delete(instanceOrIid: T | string): void;
|
|
32
|
+
}
|
|
33
|
+
export declare class TypedRelationManager<T extends IidBearing> {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(modelClass: RelationConstructor<T>, connection: ManagerConnection);
|
|
36
|
+
insert(instance: T): T;
|
|
37
|
+
insertMany(instances: readonly T[]): T[];
|
|
38
|
+
put(instance: T): T;
|
|
39
|
+
putMany(instances: readonly T[]): T[];
|
|
40
|
+
update(instance: T): T;
|
|
41
|
+
get(filters?: ExactFilters<T> | null): T[];
|
|
42
|
+
all(): T[];
|
|
43
|
+
getByIid(iid: string): T | null;
|
|
44
|
+
count(filters?: ExactFilters<T> | null): bigint;
|
|
45
|
+
query(): TypedQuery<T, DynamicRelationRow>;
|
|
46
|
+
delete(instanceOrIid: T | string): void;
|
|
47
|
+
}
|
|
48
|
+
export declare function entityManagerFor<T extends IidBearing>(modelClass: EntityConstructor<T>, connection: ManagerConnection): TypedEntityManager<T>;
|
|
49
|
+
export declare function relationManagerFor<T extends IidBearing>(modelClass: RelationConstructor<T>, connection: ManagerConnection): TypedRelationManager<T>;
|
|
50
|
+
export declare function buildRolePlayers(instance: IidBearing, schema: RelationSchema): RolePlayerInput[];
|
|
51
|
+
export {};
|