@type-bridge/node 1.5.0 → 1.5.2
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 +5 -1
- package/dist/generator/index.d.ts +46 -30
- package/dist/generator/index.js +35 -43
- package/dist/index.d.ts +16 -3
- package/dist/index.js +16 -3
- package/dist/type-bridge-node-1.5.2.tgz +0 -0
- package/package.json +1 -1
- package/type_bridge_node.linux-x64-gnu.node +0 -0
- package/dist/generator/cardinality.d.ts +0 -15
- package/dist/generator/cardinality.js +0 -28
- package/dist/generator/renderAttributes.d.ts +0 -22
- package/dist/generator/renderAttributes.js +0 -153
- package/dist/generator/renderEntities.d.ts +0 -39
- package/dist/generator/renderEntities.js +0 -273
- package/dist/generator/renderPackage.d.ts +0 -22
- package/dist/generator/renderPackage.js +0 -33
- package/dist/generator/renderRelations.d.ts +0 -36
- package/dist/generator/renderRelations.js +0 -395
- package/dist/type-bridge-node-1.5.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -60,7 +60,11 @@ const person = registry.registerEntity({
|
|
|
60
60
|
const attrs = { name: string("Alice"), age: long(42n) };
|
|
61
61
|
new Marshalling().entityAttributes(person, attrs);
|
|
62
62
|
|
|
63
|
-
const db = RustDatabase.connect("127.0.0.1:1729", "example"
|
|
63
|
+
const db = RustDatabase.connect("127.0.0.1:1729", "example", {
|
|
64
|
+
httpPort: 8000,
|
|
65
|
+
// Optional: skip HTTP probing when only gRPC is reachable.
|
|
66
|
+
serverVersion: "3.11.5",
|
|
67
|
+
});
|
|
64
68
|
const manager = db.entityManager(person);
|
|
65
69
|
manager.insert(attrs);
|
|
66
70
|
```
|
|
@@ -1,44 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TypeScript model generator
|
|
2
|
+
* TypeScript model generator facade.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `.ts` surface to a caller-supplied output directory.
|
|
7
|
-
*
|
|
8
|
-
* The native module is INJECTED (not self-resolved) — callers load the native
|
|
9
|
-
* module via the package root's `loadNative()` and pass the `SchemaParserNative`
|
|
10
|
-
* slice in `options.native`. This keeps the generator free of any native-resolution
|
|
11
|
-
* path, so it survives the package layout change.
|
|
12
|
-
*
|
|
13
|
-
* Generated files import from `@type-bridge/node` (package entrypoint), never
|
|
14
|
-
* from a hardcoded relative path, so they are valid across packaging layout changes.
|
|
15
|
-
*
|
|
16
|
-
* Build-time code generation; no runtime ORM logic.
|
|
4
|
+
* Rendering is owned by the Rust bindgen engine. This module only injects the
|
|
5
|
+
* native module, requests a target package, and writes returned files.
|
|
17
6
|
*/
|
|
18
|
-
import { type SchemaParserNative } from "../parser.js";
|
|
19
7
|
import type { NamingOptions } from "./naming.js";
|
|
8
|
+
/** Output targets supported by the Rust bindgen engine. */
|
|
9
|
+
export type BindgenTarget = "python" | "typescript" | "rust";
|
|
10
|
+
/** One generated source file returned by the native bindgen engine. */
|
|
11
|
+
export interface GeneratedFile {
|
|
12
|
+
/** Relative output path. */
|
|
13
|
+
path: string;
|
|
14
|
+
/** Complete source text. */
|
|
15
|
+
contents: string;
|
|
16
|
+
}
|
|
17
|
+
/** Generated package payload returned by the native bindgen engine. */
|
|
18
|
+
export interface GeneratedPackage {
|
|
19
|
+
/** Target language rendered by Rust. */
|
|
20
|
+
target: BindgenTarget;
|
|
21
|
+
/** Files to write. */
|
|
22
|
+
files: GeneratedFile[];
|
|
23
|
+
}
|
|
24
|
+
/** Native module slice required by the generator facade. */
|
|
25
|
+
export interface BindgenNative {
|
|
26
|
+
/** Render model files as a JSON {@link GeneratedPackage}. */
|
|
27
|
+
renderModelsJson(input: string, target: string, optionsJson?: string | null): string;
|
|
28
|
+
}
|
|
29
|
+
/** Shared Rust bindgen render options exposed through the TypeScript facade. */
|
|
30
|
+
export interface BindgenRenderOptions extends NamingOptions {
|
|
31
|
+
/** Schema version rendered into generated Python package metadata. */
|
|
32
|
+
schemaVersion?: string;
|
|
33
|
+
/** Bundled schema filename for generated Python `schema_text()`, or `null` to omit it. */
|
|
34
|
+
schemaFilename?: string | null;
|
|
35
|
+
/** Source schema text used by generated Python registry metadata. */
|
|
36
|
+
schemaText?: string | null;
|
|
37
|
+
}
|
|
20
38
|
/** Options for `generateModels`. */
|
|
21
|
-
export interface GenerateModelsOptions extends
|
|
39
|
+
export interface GenerateModelsOptions extends BindgenRenderOptions {
|
|
22
40
|
/**
|
|
23
|
-
* The native module slice providing `
|
|
24
|
-
* from the package root's `loadNative()` return value.
|
|
25
|
-
* generator does not self-load the native module.
|
|
41
|
+
* The native module slice providing `renderModelsJson`. Callers obtain this
|
|
42
|
+
* from the package root's `loadNative()` return value.
|
|
26
43
|
*/
|
|
27
|
-
native:
|
|
44
|
+
native: BindgenNative;
|
|
45
|
+
}
|
|
46
|
+
/** Options for cross-target model generation. */
|
|
47
|
+
export interface GenerateTargetModelsOptions extends GenerateModelsOptions {
|
|
48
|
+
/** Target language to render. */
|
|
49
|
+
target: BindgenTarget;
|
|
28
50
|
}
|
|
29
51
|
/**
|
|
30
52
|
* Generate the typed TypeScript model surface from a TQL `define` block.
|
|
31
53
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* Writes `attributes.ts`, `entities.ts`, `relations.ts`, and `index.ts`
|
|
35
|
-
* (package barrel) to `outputDir`.
|
|
36
|
-
*
|
|
37
|
-
* @param tql - TQL schema string (a `define` block).
|
|
38
|
-
* @param outputDir - Directory to write the generated `.ts` files into.
|
|
39
|
-
* Created if absent. Passed by the caller; the generator
|
|
40
|
-
* does not enforce a specific location.
|
|
41
|
-
* @param options - `native` (required) + optional `implicitKeyAttributes`.
|
|
54
|
+
* Historical entrypoint: this always targets TypeScript. Use
|
|
55
|
+
* `generateModelsForTarget` for cross-target generation.
|
|
42
56
|
*/
|
|
43
57
|
export declare function generateModels(tql: string, outputDir: string, options: GenerateModelsOptions): void;
|
|
58
|
+
/** Generate model files for any Rust-bindgen target. */
|
|
59
|
+
export declare function generateModelsForTarget(tql: string, outputDir: string, options: GenerateTargetModelsOptions): void;
|
|
44
60
|
export { toClassName, toFieldName, type NamingOptions } from "./naming.js";
|
package/dist/generator/index.js
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* TypeScript model generator
|
|
3
|
+
* TypeScript model generator facade.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `.ts` surface to a caller-supplied output directory.
|
|
8
|
-
*
|
|
9
|
-
* The native module is INJECTED (not self-resolved) — callers load the native
|
|
10
|
-
* module via the package root's `loadNative()` and pass the `SchemaParserNative`
|
|
11
|
-
* slice in `options.native`. This keeps the generator free of any native-resolution
|
|
12
|
-
* path, so it survives the package layout change.
|
|
13
|
-
*
|
|
14
|
-
* Generated files import from `@type-bridge/node` (package entrypoint), never
|
|
15
|
-
* from a hardcoded relative path, so they are valid across packaging layout changes.
|
|
16
|
-
*
|
|
17
|
-
* Build-time code generation; no runtime ORM logic.
|
|
5
|
+
* Rendering is owned by the Rust bindgen engine. This module only injects the
|
|
6
|
+
* native module, requests a target package, and writes returned files.
|
|
18
7
|
*/
|
|
19
8
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -22,43 +11,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
12
|
exports.toFieldName = exports.toClassName = void 0;
|
|
24
13
|
exports.generateModels = generateModels;
|
|
14
|
+
exports.generateModelsForTarget = generateModelsForTarget;
|
|
25
15
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
26
16
|
const node_path_1 = __importDefault(require("node:path"));
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
function requestGeneratedPackage(tql, options, target) {
|
|
18
|
+
const payload = {
|
|
19
|
+
implicit_key_attributes: options.implicitKeyAttributes ?? [],
|
|
20
|
+
};
|
|
21
|
+
if (options.schemaVersion !== undefined) {
|
|
22
|
+
payload.schema_version = options.schemaVersion;
|
|
23
|
+
}
|
|
24
|
+
if (options.schemaFilename !== undefined) {
|
|
25
|
+
payload.schema_filename = options.schemaFilename;
|
|
26
|
+
}
|
|
27
|
+
if (options.schemaText !== undefined) {
|
|
28
|
+
payload.schema_text = options.schemaText;
|
|
29
|
+
}
|
|
30
|
+
return JSON.parse(options.native.renderModelsJson(tql, target, JSON.stringify(payload)));
|
|
31
|
+
}
|
|
32
|
+
function writePackage(outputDir, generated) {
|
|
33
|
+
node_fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
34
|
+
for (const file of generated.files) {
|
|
35
|
+
const filePath = node_path_1.default.join(outputDir, file.path);
|
|
36
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true });
|
|
37
|
+
node_fs_1.default.writeFileSync(filePath, file.contents, "utf-8");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
32
40
|
/**
|
|
33
41
|
* Generate the typed TypeScript model surface from a TQL `define` block.
|
|
34
42
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* Writes `attributes.ts`, `entities.ts`, `relations.ts`, and `index.ts`
|
|
38
|
-
* (package barrel) to `outputDir`.
|
|
39
|
-
*
|
|
40
|
-
* @param tql - TQL schema string (a `define` block).
|
|
41
|
-
* @param outputDir - Directory to write the generated `.ts` files into.
|
|
42
|
-
* Created if absent. Passed by the caller; the generator
|
|
43
|
-
* does not enforce a specific location.
|
|
44
|
-
* @param options - `native` (required) + optional `implicitKeyAttributes`.
|
|
43
|
+
* Historical entrypoint: this always targets TypeScript. Use
|
|
44
|
+
* `generateModelsForTarget` for cross-target generation.
|
|
45
45
|
*/
|
|
46
46
|
function generateModels(tql, outputDir, options) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const relationSource = (0, renderRelations_js_1.renderRelations)(schema, options);
|
|
53
|
-
const packageSource = (0, renderPackage_js_1.renderPackage)(schema);
|
|
54
|
-
// Write
|
|
55
|
-
node_fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
56
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(outputDir, "attributes.ts"), attrSource, "utf-8");
|
|
57
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(outputDir, "entities.ts"), entitySource, "utf-8");
|
|
58
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(outputDir, "relations.ts"), relationSource, "utf-8");
|
|
59
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(outputDir, "index.ts"), packageSource, "utf-8");
|
|
47
|
+
writePackage(outputDir, requestGeneratedPackage(tql, options, "typescript"));
|
|
48
|
+
}
|
|
49
|
+
/** Generate model files for any Rust-bindgen target. */
|
|
50
|
+
function generateModelsForTarget(tql, outputDir, options) {
|
|
51
|
+
writePackage(outputDir, requestGeneratedPackage(tql, options, options.target));
|
|
60
52
|
}
|
|
61
|
-
// Re-export the naming utilities and options type for callers that need them
|
|
53
|
+
// Re-export the naming utilities and options type for callers that need them.
|
|
62
54
|
var naming_js_1 = require("./naming.js");
|
|
63
55
|
Object.defineProperty(exports, "toClassName", { enumerable: true, get: function () { return naming_js_1.toClassName; } });
|
|
64
56
|
Object.defineProperty(exports, "toFieldName", { enumerable: true, get: function () { return naming_js_1.toFieldName; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -298,6 +298,10 @@ interface NativeMarshalling {
|
|
|
298
298
|
export interface NativeRustDatabase {
|
|
299
299
|
isConnected(): boolean;
|
|
300
300
|
databaseName(): string;
|
|
301
|
+
databaseExists(): boolean;
|
|
302
|
+
createDatabase(): void;
|
|
303
|
+
deleteDatabase(): void;
|
|
304
|
+
resetDatabase(): void;
|
|
301
305
|
transaction(transactionType?: TransactionType): NativeRustTransactionContext;
|
|
302
306
|
entityManagerJson(descriptorJson: string): NativeDynamicEntityManager;
|
|
303
307
|
relationManagerJson(descriptorJson: string): NativeDynamicRelationManager;
|
|
@@ -349,11 +353,12 @@ export interface NativeDynamicRelationManager {
|
|
|
349
353
|
queryGroupByAggregateJson(specJson: string, groupFieldsJson: string, aggregatesJson: string): string;
|
|
350
354
|
}
|
|
351
355
|
export interface NativeRuntime {
|
|
352
|
-
ensureRustDatabase(address: string, database: string, username?: string | null, password?: string | null, httpPort?: number | null): void;
|
|
353
|
-
connectRustDatabase(address: string, database: string, username?: string | null, password?: string | null, httpPort?: number | null): NativeRustDatabase;
|
|
356
|
+
ensureRustDatabase(address: string, database: string, username?: string | null, password?: string | null, httpPort?: number | null, serverVersion?: string | null): void;
|
|
357
|
+
connectRustDatabase(address: string, database: string, username?: string | null, password?: string | null, httpPort?: number | null, serverVersion?: string | null): NativeRustDatabase;
|
|
354
358
|
}
|
|
355
359
|
interface NativeSchemaParser {
|
|
356
360
|
parseSchemaJson(input: string): string;
|
|
361
|
+
renderModelsJson(input: string, target: string, optionsJson?: string | null): string;
|
|
357
362
|
}
|
|
358
363
|
export interface NativeModule extends NativeRuntime, NativeMarshalling, NativeSchemaParser {
|
|
359
364
|
NodeDescriptorRegistry: new () => NativeDescriptorRegistry;
|
|
@@ -364,12 +369,16 @@ export interface RustDatabaseConnectOptions {
|
|
|
364
369
|
password?: string | null;
|
|
365
370
|
/** Port of the TypeDB HTTP API used for the connect-time version probe. */
|
|
366
371
|
httpPort?: number;
|
|
372
|
+
/** Exact TypeDB server version; skips HTTP probing for gRPC-only deployments. */
|
|
373
|
+
serverVersion?: string | null;
|
|
367
374
|
}
|
|
368
375
|
export interface EnsureDatabaseOptions {
|
|
369
376
|
username?: string | null;
|
|
370
377
|
password?: string | null;
|
|
371
378
|
/** Port of the TypeDB HTTP API used for the connect-time version probe. */
|
|
372
379
|
httpPort?: number;
|
|
380
|
+
/** Exact TypeDB server version; skips HTTP probing for gRPC-only deployments. */
|
|
381
|
+
serverVersion?: string | null;
|
|
373
382
|
}
|
|
374
383
|
/**
|
|
375
384
|
* Ensure the named TypeDB database exists, creating it if absent.
|
|
@@ -410,6 +419,10 @@ export declare class RustDatabase {
|
|
|
410
419
|
static connect(native: NativeRuntime, address: string, database: string, options?: RustDatabaseConnectOptions): RustDatabase;
|
|
411
420
|
isConnected(): boolean;
|
|
412
421
|
databaseName(): string;
|
|
422
|
+
databaseExists(): boolean;
|
|
423
|
+
createDatabase(): void;
|
|
424
|
+
deleteDatabase(): void;
|
|
425
|
+
resetDatabase(): void;
|
|
413
426
|
transaction(transactionType?: TransactionType): RustTransactionContext;
|
|
414
427
|
entityManager(descriptor: EntityDescriptor): RustDynamicEntityManager;
|
|
415
428
|
relationManager(descriptor: RelationDescriptor): RustDynamicRelationManager;
|
|
@@ -466,4 +479,4 @@ export declare class RustDynamicRelationManager {
|
|
|
466
479
|
queryGroupByAggregate(spec: DynamicQuerySpec, groupFields: string[], aggregates: AggregateInput[]): unknown[];
|
|
467
480
|
deleteByIid(iid: string): void;
|
|
468
481
|
}
|
|
469
|
-
export { generateModels, type GenerateModelsOptions, type NamingOptions, } from "./generator/index.js";
|
|
482
|
+
export { generateModels, generateModelsForTarget, type BindgenRenderOptions, type BindgenTarget, type GenerateModelsOptions, type GenerateTargetModelsOptions, type NamingOptions, } from "./generator/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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;
|
|
4
|
+
exports.generateModelsForTarget = exports.generateModels = exports.RustDynamicRelationManager = void 0;
|
|
5
5
|
exports.string = string;
|
|
6
6
|
exports.long = long;
|
|
7
7
|
exports.longFromNumberUnsafe = longFromNumberUnsafe;
|
|
@@ -117,7 +117,7 @@ function duration(value) {
|
|
|
117
117
|
* silent skip.
|
|
118
118
|
*/
|
|
119
119
|
function ensureDatabase(address, database, options) {
|
|
120
|
-
(0, native_js_1.loadNative)().ensureRustDatabase(address, database, options?.username ?? null, options?.password ?? null, options?.httpPort ?? null);
|
|
120
|
+
(0, native_js_1.loadNative)().ensureRustDatabase(address, database, options?.username ?? null, options?.password ?? null, options?.httpPort ?? null, options?.serverVersion ?? null);
|
|
121
121
|
}
|
|
122
122
|
function generateDefineBlock(info) {
|
|
123
123
|
return (0, native_js_1.loadNative)().generateDefineBlockJson(JSON.stringify(info));
|
|
@@ -259,7 +259,7 @@ class RustDatabase {
|
|
|
259
259
|
}
|
|
260
260
|
static connect(nativeOrAddress, addressOrDatabase, databaseOrOptions = {}, maybeOptions = {}) {
|
|
261
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));
|
|
262
|
+
return new RustDatabase(parsed.native.connectRustDatabase(parsed.address, parsed.database, parsed.options.username ?? null, parsed.options.password ?? null, parsed.options.httpPort ?? null, parsed.options.serverVersion ?? null));
|
|
263
263
|
}
|
|
264
264
|
isConnected() {
|
|
265
265
|
return this.#native.isConnected();
|
|
@@ -267,6 +267,18 @@ class RustDatabase {
|
|
|
267
267
|
databaseName() {
|
|
268
268
|
return this.#native.databaseName();
|
|
269
269
|
}
|
|
270
|
+
databaseExists() {
|
|
271
|
+
return this.#native.databaseExists();
|
|
272
|
+
}
|
|
273
|
+
createDatabase() {
|
|
274
|
+
this.#native.createDatabase();
|
|
275
|
+
}
|
|
276
|
+
deleteDatabase() {
|
|
277
|
+
this.#native.deleteDatabase();
|
|
278
|
+
}
|
|
279
|
+
resetDatabase() {
|
|
280
|
+
this.#native.resetDatabase();
|
|
281
|
+
}
|
|
270
282
|
transaction(transactionType = "read") {
|
|
271
283
|
return new RustTransactionContext(this.#native.transaction(transactionType));
|
|
272
284
|
}
|
|
@@ -449,3 +461,4 @@ function parseConnectArguments(nativeOrAddress, addressOrDatabase, databaseOrOpt
|
|
|
449
461
|
// ---------------------------------------------------------------------------
|
|
450
462
|
var index_js_1 = require("./generator/index.js");
|
|
451
463
|
Object.defineProperty(exports, "generateModels", { enumerable: true, get: function () { return index_js_1.generateModels; } });
|
|
464
|
+
Object.defineProperty(exports, "generateModelsForTarget", { enumerable: true, get: function () { return index_js_1.generateModelsForTarget; } });
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared cardinality predicate helpers for TypeScript code generation.
|
|
3
|
-
*
|
|
4
|
-
* Used by both renderEntities.ts and renderRelations.ts. Each predicate
|
|
5
|
-
* mirrors the corresponding Python `Cardinality` property in models.py.
|
|
6
|
-
*/
|
|
7
|
-
import type { Cardinality } from "../parser.js";
|
|
8
|
-
/** True if at most one value is allowed (max === 1). */
|
|
9
|
-
export declare function isCardSingle(c: Cardinality): boolean;
|
|
10
|
-
/** True if at least one value is required (min >= 1). */
|
|
11
|
-
export declare function isCardRequired(c: Cardinality): boolean;
|
|
12
|
-
/** True if multiple values are allowed (max === null || max > 1). */
|
|
13
|
-
export declare function isCardMulti(c: Cardinality): boolean;
|
|
14
|
-
/** True if zero or one value (min === 0, max === 1) — the optional-single case. */
|
|
15
|
-
export declare function isCardOptionalSingle(c: Cardinality): boolean;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Shared cardinality predicate helpers for TypeScript code generation.
|
|
4
|
-
*
|
|
5
|
-
* Used by both renderEntities.ts and renderRelations.ts. Each predicate
|
|
6
|
-
* mirrors the corresponding Python `Cardinality` property in models.py.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.isCardSingle = isCardSingle;
|
|
10
|
-
exports.isCardRequired = isCardRequired;
|
|
11
|
-
exports.isCardMulti = isCardMulti;
|
|
12
|
-
exports.isCardOptionalSingle = isCardOptionalSingle;
|
|
13
|
-
/** True if at most one value is allowed (max === 1). */
|
|
14
|
-
function isCardSingle(c) {
|
|
15
|
-
return c.max === 1;
|
|
16
|
-
}
|
|
17
|
-
/** True if at least one value is required (min >= 1). */
|
|
18
|
-
function isCardRequired(c) {
|
|
19
|
-
return c.min >= 1;
|
|
20
|
-
}
|
|
21
|
-
/** True if multiple values are allowed (max === null || max > 1). */
|
|
22
|
-
function isCardMulti(c) {
|
|
23
|
-
return c.max === null || c.max > 1;
|
|
24
|
-
}
|
|
25
|
-
/** True if zero or one value (min === 0, max === 1) — the optional-single case. */
|
|
26
|
-
function isCardOptionalSingle(c) {
|
|
27
|
-
return c.min === 0 && c.max === 1;
|
|
28
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Render the `attributes.ts` module text from a parsed TypeSchema.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors `type_bridge/generator/render/attributes.py` → `render_attributes()`.
|
|
5
|
-
* Emits one branded `export class <ClassName> extends attr.<Kind>("<name>", ...) {}`
|
|
6
|
-
* per attribute, in deterministic parent-before-child order matching the
|
|
7
|
-
* Python generator's topological/sorted emit.
|
|
8
|
-
*
|
|
9
|
-
* Build-time code generation; no runtime ORM logic.
|
|
10
|
-
*/
|
|
11
|
-
import type { TypeSchema } from "../parser.js";
|
|
12
|
-
/**
|
|
13
|
-
* Render the complete `attributes.ts` source text from the parsed schema.
|
|
14
|
-
*
|
|
15
|
-
* Each attribute emits:
|
|
16
|
-
* export class <ClassName> extends attr.<Kind>("<schema-name>") {}
|
|
17
|
-
*
|
|
18
|
-
* The import header always uses the PACKAGE ENTRYPOINT `@type-bridge/node`,
|
|
19
|
-
* never a hardcoded relative path, so generated files stay valid across
|
|
20
|
-
* the packaging layout change.
|
|
21
|
-
*/
|
|
22
|
-
export declare function renderAttributes(schema: TypeSchema): string;
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Render the `attributes.ts` module text from a parsed TypeSchema.
|
|
4
|
-
*
|
|
5
|
-
* Mirrors `type_bridge/generator/render/attributes.py` → `render_attributes()`.
|
|
6
|
-
* Emits one branded `export class <ClassName> extends attr.<Kind>("<name>", ...) {}`
|
|
7
|
-
* per attribute, in deterministic parent-before-child order matching the
|
|
8
|
-
* Python generator's topological/sorted emit.
|
|
9
|
-
*
|
|
10
|
-
* Build-time code generation; no runtime ORM logic.
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.renderAttributes = renderAttributes;
|
|
14
|
-
const naming_js_1 = require("./naming.js");
|
|
15
|
-
/**
|
|
16
|
-
* Map TypeDB `value_type` strings to the `attr.*` factory method name.
|
|
17
|
-
*
|
|
18
|
-
* Verified against `typescript/attribute.ts` `attr` export:
|
|
19
|
-
* attr.String -> "string"
|
|
20
|
-
* attr.Integer -> "long" (bigint, maps to the `long` wire type)
|
|
21
|
-
* attr.Double -> "double"
|
|
22
|
-
* attr.Boolean -> "boolean"
|
|
23
|
-
* attr.Date -> "date"
|
|
24
|
-
* attr.DateTime -> "datetime"
|
|
25
|
-
* attr.DateTimeTZ -> "datetime-tz"
|
|
26
|
-
* attr.Decimal -> "decimal"
|
|
27
|
-
* attr.Duration -> "duration"
|
|
28
|
-
*
|
|
29
|
-
* The parsed schema preserves the declared value_type: an integer attribute
|
|
30
|
-
* arrives as "integer", not "long". Both "integer" and "long" map to attr.Integer
|
|
31
|
-
* (whose descriptor records the "long" wire type), mirroring the Python generator.
|
|
32
|
-
*/
|
|
33
|
-
const VALUE_TYPE_TO_KIND = {
|
|
34
|
-
string: "String",
|
|
35
|
-
integer: "Integer",
|
|
36
|
-
long: "Integer",
|
|
37
|
-
double: "Double",
|
|
38
|
-
boolean: "Boolean",
|
|
39
|
-
date: "Date",
|
|
40
|
-
datetime: "DateTime",
|
|
41
|
-
"datetime-tz": "DateTimeTZ",
|
|
42
|
-
decimal: "Decimal",
|
|
43
|
-
duration: "Duration",
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Resolve the `attr.*` factory kind for an attribute, following value_type
|
|
47
|
-
* inheritance. Mirrors `_resolve_value_type` in `render/attributes.py`.
|
|
48
|
-
*/
|
|
49
|
-
function resolveAttrKind(attrName, schema, visited = new Set()) {
|
|
50
|
-
if (visited.has(attrName))
|
|
51
|
-
return "String";
|
|
52
|
-
visited.add(attrName);
|
|
53
|
-
const attr = schema.attributes[attrName];
|
|
54
|
-
if (!attr)
|
|
55
|
-
return "String";
|
|
56
|
-
if (attr.value_type) {
|
|
57
|
-
const kind = VALUE_TYPE_TO_KIND[attr.value_type];
|
|
58
|
-
if (kind === undefined) {
|
|
59
|
-
// Fail loudly rather than emit a silently-wrong attr.String — an
|
|
60
|
-
// unmapped value_type means a TypeDB type the generator does not handle.
|
|
61
|
-
throw new Error(`Cannot generate attribute "${attrName}": unsupported value_type "${attr.value_type}".`);
|
|
62
|
-
}
|
|
63
|
-
return kind;
|
|
64
|
-
}
|
|
65
|
-
if (attr.parent) {
|
|
66
|
-
return resolveAttrKind(attr.parent, schema, visited);
|
|
67
|
-
}
|
|
68
|
-
return "String";
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Return attribute names in deterministic topological order: parents before
|
|
72
|
-
* children, with alphabetical order among unrelated attributes.
|
|
73
|
-
*/
|
|
74
|
-
function sortedAttrNames(schema) {
|
|
75
|
-
const sorted = [];
|
|
76
|
-
const visited = new Set();
|
|
77
|
-
const names = Object.keys(schema.attributes).sort();
|
|
78
|
-
function visit(name) {
|
|
79
|
-
if (visited.has(name))
|
|
80
|
-
return;
|
|
81
|
-
visited.add(name);
|
|
82
|
-
const parent = schema.attributes[name]?.parent;
|
|
83
|
-
if (parent && schema.attributes[parent]) {
|
|
84
|
-
visit(parent);
|
|
85
|
-
}
|
|
86
|
-
sorted.push(name);
|
|
87
|
-
}
|
|
88
|
-
for (const name of names) {
|
|
89
|
-
visit(name);
|
|
90
|
-
}
|
|
91
|
-
return sorted;
|
|
92
|
-
}
|
|
93
|
-
function attributeOptionsLiteral(attrName, schema, attrClassMap) {
|
|
94
|
-
const attribute = schema.attributes[attrName];
|
|
95
|
-
if (!attribute)
|
|
96
|
-
return "";
|
|
97
|
-
const fields = [];
|
|
98
|
-
if (attribute.parent) {
|
|
99
|
-
const parentClass = attrClassMap.get(attribute.parent);
|
|
100
|
-
fields.push(parentClass
|
|
101
|
-
? `parent: ${parentClass}`
|
|
102
|
-
: `parent: ${JSON.stringify(attribute.parent)}`);
|
|
103
|
-
}
|
|
104
|
-
if (attribute.is_abstract) {
|
|
105
|
-
fields.push(`abstract: true`);
|
|
106
|
-
}
|
|
107
|
-
if (attribute.is_independent) {
|
|
108
|
-
fields.push(`independent: true`);
|
|
109
|
-
}
|
|
110
|
-
if (attribute.regex !== null) {
|
|
111
|
-
fields.push(`regex: ${JSON.stringify(attribute.regex)}`);
|
|
112
|
-
}
|
|
113
|
-
if (attribute.allowed_values !== null) {
|
|
114
|
-
fields.push(`values: ${JSON.stringify(attribute.allowed_values)}`);
|
|
115
|
-
}
|
|
116
|
-
if (attribute.range_min !== null || attribute.range_max !== null) {
|
|
117
|
-
fields.push(`range: [${optionalStringLiteral(attribute.range_min)}, ${optionalStringLiteral(attribute.range_max)}]`);
|
|
118
|
-
}
|
|
119
|
-
return fields.length === 0 ? "" : `, { ${fields.join(", ")} }`;
|
|
120
|
-
}
|
|
121
|
-
function optionalStringLiteral(value) {
|
|
122
|
-
return value === null ? "null" : JSON.stringify(value);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Render the complete `attributes.ts` source text from the parsed schema.
|
|
126
|
-
*
|
|
127
|
-
* Each attribute emits:
|
|
128
|
-
* export class <ClassName> extends attr.<Kind>("<schema-name>") {}
|
|
129
|
-
*
|
|
130
|
-
* The import header always uses the PACKAGE ENTRYPOINT `@type-bridge/node`,
|
|
131
|
-
* never a hardcoded relative path, so generated files stay valid across
|
|
132
|
-
* the packaging layout change.
|
|
133
|
-
*/
|
|
134
|
-
function renderAttributes(schema) {
|
|
135
|
-
const names = sortedAttrNames(schema);
|
|
136
|
-
const attrClassMap = new Map();
|
|
137
|
-
for (const name of Object.keys(schema.attributes)) {
|
|
138
|
-
attrClassMap.set(name, (0, naming_js_1.toClassName)(name));
|
|
139
|
-
}
|
|
140
|
-
const lines = [
|
|
141
|
-
`import { attr } from "@type-bridge/node";`,
|
|
142
|
-
``,
|
|
143
|
-
];
|
|
144
|
-
for (const name of names) {
|
|
145
|
-
const className = attrClassMap.get(name) ?? (0, naming_js_1.toClassName)(name);
|
|
146
|
-
const kind = resolveAttrKind(name, schema);
|
|
147
|
-
const options = attributeOptionsLiteral(name, schema, attrClassMap);
|
|
148
|
-
lines.push(`export class ${className} extends attr.${kind}("${name}"${options}) {}`);
|
|
149
|
-
}
|
|
150
|
-
// Trailing newline
|
|
151
|
-
lines.push(``);
|
|
152
|
-
return lines.join("\n");
|
|
153
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Render the `entities.ts` module text from a parsed TypeSchema.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors `type_bridge/generator/render/entities.py` → `render_entities()`.
|
|
5
|
-
* Field KEY decision logic is ported directly from `_render_attr_field`:
|
|
6
|
-
*
|
|
7
|
-
* 1. is_key (schema @key OR implicit key) → field(Attr, Key)
|
|
8
|
-
* 2. is_unique (schema @unique) → field(Attr, Unique)
|
|
9
|
-
* 3. cardinality === null || is_optional_single (min=0, max=1)
|
|
10
|
-
* → field(Attr).optional()
|
|
11
|
-
* 4. is_multi (max === null || max > 1) → field(Attr).list(Card(min, max))
|
|
12
|
-
* 5. is_required && is_single (min>=1, max=1) → field(Attr) (plain required)
|
|
13
|
-
* 6. fallback → field(Attr).optional()
|
|
14
|
-
*
|
|
15
|
-
* Field keys = toFieldName(attr_name) — prefix kept, no pluralization.
|
|
16
|
-
*
|
|
17
|
-
* Build-time code generation; no runtime ORM logic.
|
|
18
|
-
*/
|
|
19
|
-
import type { TypeSchema } from "../parser.js";
|
|
20
|
-
import { type NamingOptions } from "./naming.js";
|
|
21
|
-
/**
|
|
22
|
-
* Render the complete `entities.ts` source text from the parsed schema.
|
|
23
|
-
*
|
|
24
|
-
* Each entity emits:
|
|
25
|
-
* export class <ClassName> extends Entity("<schema-name>", { ... }) {}
|
|
26
|
-
* or for abstract entities:
|
|
27
|
-
* export class <ClassName> extends Entity(TypeFlags({ name: "<name>", abstract: true }), { ... }) {}
|
|
28
|
-
* and with parent:
|
|
29
|
-
* ... Entity("<name>", { ... }, { parent: <ParentClass> }) {}
|
|
30
|
-
*
|
|
31
|
-
* Field keys = toFieldName(attr_name); values = the field() expression above.
|
|
32
|
-
* Attribute imports come from "./attributes"; entity parent imports also from
|
|
33
|
-
* the same file.
|
|
34
|
-
*
|
|
35
|
-
* The import header always uses the PACKAGE ENTRYPOINT `@type-bridge/node`,
|
|
36
|
-
* never a hardcoded relative path, so generated files stay valid across
|
|
37
|
-
* the packaging layout change.
|
|
38
|
-
*/
|
|
39
|
-
export declare function renderEntities(schema: TypeSchema, options?: NamingOptions): string;
|